Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29220
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: thread pool |
| Date | 2014-07-23 08:11 +0200 |
| Organization | Clausthal University of Technology |
| Message-ID | <lqnjln$2l6e$1@ariadne.rz.tu-clausthal.de> (permalink) |
| References | <lqlna0$23fm$1@ariadne.rz.tu-clausthal.de> <lqlntl$gcc$1@dont-email.me> <lqmekf$mh1$1@online.de> <lqmhk2$pnm$1@dont-email.me> <lqmk8d$e3m$1@dont-email.me> |
[Multipart message — attachments visible in raw view] - view raw
On 2014-07-22 21:14:49 +0000, Eric Sosman said:
> On 7/22/2014 5:01 PM, Philipp Kraus wrote:
>> [... ugly double-spaced Googlejunk snipped ...]
>> My solution seems to be similar, but if I run your startThreads again
>> thet.start();
>>
>> throws the InterruptedException directly, so I do
>>
>> main()
>> {
>> Master x = new Master();
>>
>> x.startThreads(5);
>> x.stopThreads();
>> x.startThreads(5); <= this does not work because the exception is thrown
>> }
>
> Are you sure startThreads() is creating and starting brand-
> new Threads each time it's called, not re-using old Threads?
> To put it another way, are you sure stopThreads() actually stops
> all the old Threads and waits for them to finish stopping (and
> then clears its "running workers" list)?
IMHO I do this (m_runners is the threadgroup):
m_runners.interrupt();
try {
m_threadcounter.await();
} catch (InterruptedException l_exception) {
m_Logger.error(l_exception.getMessage());
}
m_threadcounter is the CountDownLatch which is initialize on the
startThreads with the number of threads and each thread
calls the countDown() method before the run is released
> I cannot imagine how a newly-created Thread would find itself
> in the interrupted state before anything interrupts it. Is there
> some other part of your program that interrupts Threads when it
> shouldn't?
I don't think so. The threads are stopped / started from the UI and I
use some external libraries.
I have build a short example under
https://github.com/flashpixx/threadtest which shows the problem (I use
Java 1.8).
I get
CSimulation@5cad8086 simulation is started with [5] threads
CWorker@18a5eea9 thread [9] starts working
CWorker@3d9bc497 thread [10] starts working
CWorker@7351b7d5 thread [11] starts working
CWorker@6605d308 thread [12] starts working
CWorker@6826907c thread [13] starts working
CWorker@6605d308 thread [12] stops working with current count down latch [3]
CWorker@18a5eea9 thread [9] stops working with current count down latch [3]
CWorker@7351b7d5 thread [11] stops working with current count down latch [2]
CSimulation@5cad8086 threads stopped
CWorker@3d9bc497 thread [10] stops working with current count down latch [0]
CWorker@6826907c thread [13] stops working with current count down latch [1]
CSimulation@5cad8086 simulation is stopped
CSimulation@5cad8086 simulation is started with [5] threads
CWorker@b7127ff thread [14] starts working
CWorker@6441c612 thread [15] starts working
CWorker@67d26a8e thread [16] starts working
CWorker@193fa958 thread [17] starts working
CWorker@3aa2722f thread [18] starts working
CWorker@6441c612 thread [15] stops working with current count down latch [3]
CWorker@193fa958 thread [17] stops working with current count down latch [1]
CWorker@3aa2722f thread [18] stops working with current count down latch [0]
CSimulation@5cad8086 threads stopped
CWorker@67d26a8e thread [16] stops working with current count down latch [3]
CSimulation@5cad8086 simulation is stopped
CWorker@b7127ff thread [14] stops working with current count down latch [0]
It seems, that the CountDownLatch does not work as expected. Any idea?
Phil
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-22 15:00 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-22 09:11 -0400
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-22 16:32 +0200
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-22 21:38 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-22 16:29 -0400
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-22 23:01 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-22 17:14 -0400
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-23 08:11 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-23 07:24 -0400
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-23 15:57 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-23 11:41 -0400
Re: thread pool Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-24 09:55 +0200
Re: thread pool Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-24 08:39 -0400
Re: thread pool Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2014-07-24 20:50 -0700
csiph-web