dev@grizzly.java.net

Re: StateHolder doesn't handle Thread.Interrupt ?

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 29 Jun 2009 13:43:48 +0200

Hi,

> I'm using StateHolder in a project and I found that when I called
> Thread.interrupt.. it doesn't set the state to STOPPED.
Right.

> Does StateHolder can be use outside grizzly module ?
Theoretically yes.

> here a snippet
>
> public class Test implements Runnable ...
>
> while (stateHolder.getState(false) != State.STOPPED) {
>
> system.out...
> Thread.sleep(500);
> ...
> }
>
>
> public void main...
> Test test = new Test();
>
> ExecutorService threadPool = new ...
>
> threadPool.execute(test);
>
> Thread.sleep(1000);
> threadPool.shutdownNow();
>
>
> Test is still running.. should I put
>
>
>
stateHolder could represent the state of whole framework, which may
use different thread pool(s), so, IMHO, stateHolder in general should
not be used for such usecase.


> while (!Thread.interrupted() && stateHolder.getState(false) !=
> State.STOPPED) {

This should work.

Thanks.

WBR,
Alexey.