I have created a runnable jar, which runs on a single thread. The thread executes a for loop having 100 iteration. However the cpu usgae goes upto 60% on i3 processor win7 64 bit machine. I tried to analyze the cpu usage in process Explorer
The native threads are consuming CPUs. The native threads are all at msvcr100.dll!endthreadex+0x60 consuming cpu I am using jdl 1.7. Can somebody please suggest what might be going wrong here.
Here is the code: the app accepts socket connection and processes the date sent by the client.
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
}
}
I suspect that if you try this:
ex.printStackTrace();
you might get some more information. Right now, when you get an exception, you have no idea what happened or why. You are silent about it, which is rarely the right behavior for hitting exceptions.
What is the processing? If you're trying to do a lot of work, it might not be unexpected to go to 60% cpu. What's the Big O runtime of your algo? What's the data set size?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.