Note that there are some explanatory texts on larger screens.

plurals
  1. POAnalysing a multi-threaded Java application
    primarykey
    data
    text
    <p>In an open source application I'm participating, we've got a bug, where the application doesn't always close properly. That's what I'd like to solve.</p> <p>Experience has shown that this happens most of the time when threads and processes are being started, but not managed correctly (e.g. a thread is waiting on a socket connection, the application is being shut down and the thread keeps on waiting).<br> With this in mind I've searched for '.start()' in the entire source and found 53 occurrences (which scared me a bit).<br> As a first step, I wanted to create a helper class (ThreadExecutor) where the current code 'thread.start()' would be replaced by 'ThreadExecutor.Execute(thread)' to have a) only a few changes in the existing source and b) a single class where I can easily check which threads don't end as they should. To do this I wanted to</p> <ul> <li>add the thread to be executed to a list called activeThreads when calling the Execute method</li> <li>start the thread</li> <li>remove it from the activeThreads list when it ends.</li> </ul> <p>This way I'd have an up to date list of all executing threads and when the app hangs on shutdown I could see in there which thread(s) is(are) causing it.</p> <p>Questions:</p> <ul> <li>What do you think about the concept? I'm usually coding c# and know how I'd do it using .NET with workers, but am not too sure what's best in Java (I'd like to modify as few lines of code as possible in the existing source).</li> <li>If the concept seems ok, how can I get notified of a thread terminating. I'd like to avoid having an additional thread checking every once in a while what the state of all threads contained in activeThreads is, to remove them if they terminated.</li> </ul> <p>Just to clarify: Before figuring out how to terminate the application properly, what I'm asking here is what's the best/easiest way to find which threads are at cause for certain test cases which are pretty hard to reproduce.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload