我創建了一個可在單個線程上運行的可運行jar。該線程執行具有100次迭代的for循環。然而,CPU igae在i3處理器win7 64位機上高達60%。 我試圖分析process Explorer的CPU使用率javaw.exe CPU使用率高
原生線程正在消耗CPU。 本機線程都在msvcr100.dll!endthreadex + 0x60 正在使用cpu 我正在使用jdl 1.7。 有人可以請建議這裏可能會出現什麼問題。
這是代碼: 該應用程序接受套接字連接並處理客戶端發送的日期。
while (true)
{
try
{
Socket sock = ssock.accept();
// This is the function which has the for loop
obj.MyFunction();
}
catch(Exception ex)
{
ssock.close();
}
Thread.sleep(1000);
}
void MyFunction()
{
for(int i=0; i < 1000;i++)
{
// Processing done here
}
}
如果你在這裏顯示你的代碼可能會有所幫助! –
您需要JProfiler – ControlAltDel
剛剛發佈的代碼 –