我通過一些代碼去的地步,現在是不是我的。在代碼中有一個與下面的代碼線程:這是什麼休眠線程
while (true)
{
Thread.sleep(int.MaxValue);
}
它還捕捉InterruptedException的,去右後衛進入死循環,所以循環甚至不能被打斷。
有誰知道爲什麼這個線程會存在,有什麼目的?
編輯:完整的代碼,一點點更多的上下文:
using IKVM.Attributes;
using java.lang;
using System;
using System.Runtime.CompilerServices;
namespace applicationNamespace
{
internal sealed class DedicatedServerSleepThread : Thread
{
internal DedicatedServer theDecitatedServer;
[MethodImpl(MethodImplOptions.NoInlining)]
internal DedicatedServerSleepThread(DedicatedServer dedicatedServer)
{
this.theDecitatedServer = dedicatedServer;
base.setDaemon(true);
this.start();
}
[MethodImpl(MethodImplOptions.NoInlining)]
public override void run()
{
while (true)
{
try
{
while (true)
{
System.Threading.Thread.Sleep(int.MaxValue);
}
}
catch (System.Threading.ThreadInterruptedException)
{
}
}
}
static DedicatedServerSleepThread()
{
}
}
}
注意前面的代碼使用了一些非標準的庫,所以小寫的睡眠是有效的。特別是它使用了ikvm庫(基於java標準庫,並用於將java程序交叉編譯爲.net)
這是一個java服務器程序,我將其交叉編譯爲.net字節碼,然後進行反編譯。我不確定是否有人曾經見過一條專門用於睡覺的線程,如果是的話,原因是什麼。 ta.speot.is提供了一個非常好的答案。
該碼位似乎超出了上下文,因此很難猜測爲什麼以及發生了什麼。您需要提供更多信息。 – timss 2013-04-20 01:03:56
看起來毫無意義。代碼中沒有任何評論或文檔,是嗎? – Thilo 2013-04-20 01:04:18
絕對沒有用處。 – slugster 2013-04-20 01:04:27