0

I beg pardon for the english skills in advance.

For some reasons, i've realized everything in this way (essentially due to a java practical experience lack and ignorance of multithreading). This code works more or less what i've expected it should do, but it's turned out it has high cpu usage (after some changes made it's ranging from 30% to 70% now) and noticeable memory leaks (when it starts to occupy about 2 Gb of RAM everything is gradually getting bad for GUI and PC as well). I've already done everything i could to try to fix it.

I would be glad to hear any tips and what i could do in this situation (even if those are Java general tips).

/code is removed because of reducing originality of diploma/

I would like to reduce CPU usage at least to an acceptable level and what much more important i wanna get rid of the memory leaks mentioned above.

Lolizer
  • 9
  • 3
  • I'm not a java expert and haven't had time to read carefully all the code. But the usage of Thread.Sleep(..) looks weired and on other environments indicates general design issues. You have a while(true) loop in your worker that explains the high cpu usage. I expect your memory issue comes from creating more and more threads than creating a few and just handle the work to be done to them. – user743414 Apr 26 '19 at 11:06
  • @user743414 ,thanks for answering me +I get why you consider those Thread.Sleep() usages as weird.I've done it due to noticing that their lack (in some threads) slightly increases CPU usage and at one moment i just have to restrict the frequency of creating images (for example to get roughly 10 images per second). What could i do with that in your opinion? I'm ready for any suggestions (for example: you should get rid of all sleep() calls at all) +There is any other way to perform long-running task but 'while(true)' that not increases CPU usage like used one? +I'm not sure that that occurs – Lolizer Apr 26 '19 at 14:01
  • As a general advice you could create a threadpool and just handle the work to be done to the thread pool rather than create a bunch of threads and idle in them with a while(true) loop. Yeah a Thread.Sleep(..) gives away time from the current time slice which results in less cpu time speed for the thread. Do you need 10 images per second or as much as possible per second? – user743414 Apr 29 '19 at 08:43
  • Another advice would be to track construction/destruction of threads to check if your memory issues comes from there. – user743414 Apr 29 '19 at 08:51

0 Answers0