You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/10/17 12:32:21 UTC

svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Author: markt
Date: Thu Oct 17 10:32:21 2013
New Revision: 1533035

URL: http://svn.apache.org/r1533035
Log:
Avoid hangs on shutdown

Modified:
    tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java?rev=1533035&r1=1533034&r2=1533035&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java (original)
+++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java Thu Oct 17 10:32:21 2013
@@ -316,7 +316,9 @@ public final class Room {
             public void run() {
                 closed = true;
                 drawmessageBroadcastTimer.cancel();
-                roomGraphics.dispose();
+                if (!ShutdownDetection.hasShutdownStarted()) {
+                    roomGraphics.dispose();
+                }
             }
         });
     }
@@ -412,4 +414,23 @@ public final class Room {
             client.sendMessage(new StringWebsocketMessage(completeMsg));
         }
     }
+    
+    
+    static {
+        Runtime.getRuntime().addShutdownHook(new ShutdownDetection());
+    }
+    
+    
+    private static class ShutdownDetection extends Thread {
+        private static volatile boolean shutdownStarted = false;
+        
+        private static boolean hasShutdownStarted() {
+            return shutdownStarted;
+        }
+        
+        @Override
+        public void run() {
+            shutdownStarted = true;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Konstantin,

On 10/17/13 8:34 AM, Konstantin Preißer wrote:
> Mark,
> 
>> -----Original Message-----
>> From: Mark Thomas [mailto:markt@apache.org]
>> Sent: Thursday, October 17, 2013 1:30 PM
>> To: Tomcat Developers List
>> Subject: Re: svn commit: r1533035 -
>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>> INF/classes/websocket/drawboard/Room.java
>>
>>
>> OK. I think I'm done.
>>
>> Mark
> 
> Thanks a lot. (I probably should have though of using lazy initializing also when creating the room implementation, so e.g. the memory for the BufferedImage is not created until the Drawboard is actually used :)

... or, you could always dispense with the server-side image altogether ;)

-chris


RE: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Konstantin Preißer <kp...@apache.org>.
Mark,

> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Thursday, October 17, 2013 1:30 PM
> To: Tomcat Developers List
> Subject: Re: svn commit: r1533035 -
> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> INF/classes/websocket/drawboard/Room.java
> 
> 
> OK. I think I'm done.
> 
> Mark

Thanks a lot. (I probably should have though of using lazy initializing also when creating the room implementation, so e.g. the memory for the BufferedImage is not created until the Drawboard is actually used :)


Regards,
Konstantin Preißer


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2013 12:21, Konstantin Preißer wrote:
> 
> 
>> -----Original Message-----
>> From: Konstantin Preißer [mailto:kpreisser@apache.org]
>> Sent: Thursday, October 17, 2013 1:18 PM
>> To: 'Tomcat Developers List'
>> Subject: RE: svn commit: r1533035 -
>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>> INF/classes/websocket/drawboard/Room.java
>>
>> Hi Mark,
>>
>>> -----Original Message-----
>>> From: Mark Thomas [mailto:markt@apache.org]
>>> Sent: Thursday, October 17, 2013 1:10 PM
>>> To: Tomcat Developers List
>>> Subject: Re: svn commit: r1533035 -
>>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>>> INF/classes/websocket/drawboard/Room.java
>>>
>>> On 17/10/2013 11:53, Mark Thomas wrote:
>>>> On 17/10/2013 11:50, Konstantin Preißer wrote:
>>>>> Hi Mark,
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Mark Thomas [mailto:markt@apache.org]
>>>>>> Sent: Thursday, October 17, 2013 12:49 PM
>>>>>> To: Tomcat Developers List
>>>>>> Subject: Re: svn commit: r1533035 -
>>>>>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>>>>>> INF/classes/websocket/drawboard/Room.java
>>>>>>
>>>>>> On 17/10/2013 11:39, Konstantin Kolinko wrote:
>>>>>>> 2013/10/17  <ma...@apache.org>:
>>>>>>>> Author: markt
>>>>>>>> Date: Thu Oct 17 10:32:21 2013
>>>>>>>> New Revision: 1533035
>>>>>>>>
>>>>>>>> URL: http://svn.apache.org/r1533035
>>>>>>>> Log:
>>>>>>>> Avoid hangs on shutdown
>>>>>>>>
>>>>>>>> Modified:
>>>>>>>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>>>>>> INF/classes/websocket/drawboard/Room.java
>>>>>>>>
>>>>>>>
>>>>>>> I expect this to
>>>>>>> a) fail when running with a security manager
>>>>>>> b) cause a memory leak when examples app is reloaded, as you will
>> get
>>>>>>> a new instance of ShutdownDetection class in webapp's classloader
>>> and
>>>>>>> new instance of shutdown hook.
>>>>>>
>>>>>> I'm open to better suggestions. Another option I considered was just
>>>>>> removing the call to roomGraphics.dispose(); and letting GC take care
>> of
>>>>>> things.
>>>>>>
>>>>>> Alternatively, we could provide some form of global flag.
>>>>>>
>>>>>> I think I prefer the global flag that indicates that a shutdown is in
>>>>>> process. I can think of several other places where such a flag would
>>>>>> have been useful and we can expose it through a custom servlet
>> context
>>>>>> attribute such as
>>> "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
>>>>>>
>>>>>> I'll start looking at the global flag option. Meanwhile, any suggestions
>>>>>> on how to improve the fix or an alternative fix welcome.
>>>>>
>>>>> Can you give me some insight of why Grahpics2D.dispose() may cause a
>>> hang on shutdown? I have never seen .dispose() causing a hang, at least
>> not
>>> on Windows.
>>>>> If it hangs, might this be a result of different threads using the Grahpics
>>> object?
>>>>
>>>> Clean 7.0.x build
>>>> catalina.bat start
>>>> CTRL-C in the Tomcat Window
>>>>
>>>> The result is an exception written to stderr (I assume err rather than
>>>> out) and Tomcat fails to stop. The exception is triggered by AWT trying
>>>> to register a shutdown hook after the shutdown process has started.
>>>
>>> Ah. More info. It only occurs with Java 6.
>>>
>>> We could just classify this as a JVM bug and more on. That said, I think
>>> some changes to the init code could probably avoid this in Java 6 as
>>> well. I'll take a quick look.
>>
>> OK, thanks.
>> However, I can reproduce the hang now with Tomcat 7 on Java 7. Although I
>> do not get a exception, I get a short hang and a warning: "The executor
>> associated with thread pool [http-bio-8080] has not fully shutdown. Some
>> application threads may still be running." After that, Tomcat closed.
>> I do not get this with Tomcat 8.
>>
>> My reaction also would have been to just remove the dispose() in the
>> Tomcat 7 example since it is unlikely that the examples application is
>> reloaded many times on a Tomcat run and creates too much Graphics2D
>> objects that the GC does not dispose. But of course, I have nothing against a
>> better solution if you find one. :)
> 
> OK, that was not the full story:
> 
> I can reproduce the short hang (and the warning) on Tomcat 8 with BIO connector, but not with NIO or APR...

OK. I think I'm done.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


RE: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Konstantin Preißer <kp...@apache.org>.

> -----Original Message-----
> From: Konstantin Preißer [mailto:kpreisser@apache.org]
> Sent: Thursday, October 17, 2013 1:18 PM
> To: 'Tomcat Developers List'
> Subject: RE: svn commit: r1533035 -
> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> INF/classes/websocket/drawboard/Room.java
> 
> Hi Mark,
> 
> > -----Original Message-----
> > From: Mark Thomas [mailto:markt@apache.org]
> > Sent: Thursday, October 17, 2013 1:10 PM
> > To: Tomcat Developers List
> > Subject: Re: svn commit: r1533035 -
> > /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> > INF/classes/websocket/drawboard/Room.java
> >
> > On 17/10/2013 11:53, Mark Thomas wrote:
> > > On 17/10/2013 11:50, Konstantin Preißer wrote:
> > >> Hi Mark,
> > >>
> > >>> -----Original Message-----
> > >>> From: Mark Thomas [mailto:markt@apache.org]
> > >>> Sent: Thursday, October 17, 2013 12:49 PM
> > >>> To: Tomcat Developers List
> > >>> Subject: Re: svn commit: r1533035 -
> > >>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> > >>> INF/classes/websocket/drawboard/Room.java
> > >>>
> > >>> On 17/10/2013 11:39, Konstantin Kolinko wrote:
> > >>>> 2013/10/17  <ma...@apache.org>:
> > >>>>> Author: markt
> > >>>>> Date: Thu Oct 17 10:32:21 2013
> > >>>>> New Revision: 1533035
> > >>>>>
> > >>>>> URL: http://svn.apache.org/r1533035
> > >>>>> Log:
> > >>>>> Avoid hangs on shutdown
> > >>>>>
> > >>>>> Modified:
> > >>>>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> > >>> INF/classes/websocket/drawboard/Room.java
> > >>>>>
> > >>>>
> > >>>> I expect this to
> > >>>> a) fail when running with a security manager
> > >>>> b) cause a memory leak when examples app is reloaded, as you will
> get
> > >>>> a new instance of ShutdownDetection class in webapp's classloader
> > and
> > >>>> new instance of shutdown hook.
> > >>>
> > >>> I'm open to better suggestions. Another option I considered was just
> > >>> removing the call to roomGraphics.dispose(); and letting GC take care
> of
> > >>> things.
> > >>>
> > >>> Alternatively, we could provide some form of global flag.
> > >>>
> > >>> I think I prefer the global flag that indicates that a shutdown is in
> > >>> process. I can think of several other places where such a flag would
> > >>> have been useful and we can expose it through a custom servlet
> context
> > >>> attribute such as
> > "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
> > >>>
> > >>> I'll start looking at the global flag option. Meanwhile, any suggestions
> > >>> on how to improve the fix or an alternative fix welcome.
> > >>
> > >> Can you give me some insight of why Grahpics2D.dispose() may cause a
> > hang on shutdown? I have never seen .dispose() causing a hang, at least
> not
> > on Windows.
> > >> If it hangs, might this be a result of different threads using the Grahpics
> > object?
> > >
> > > Clean 7.0.x build
> > > catalina.bat start
> > > CTRL-C in the Tomcat Window
> > >
> > > The result is an exception written to stderr (I assume err rather than
> > > out) and Tomcat fails to stop. The exception is triggered by AWT trying
> > > to register a shutdown hook after the shutdown process has started.
> >
> > Ah. More info. It only occurs with Java 6.
> >
> > We could just classify this as a JVM bug and more on. That said, I think
> > some changes to the init code could probably avoid this in Java 6 as
> > well. I'll take a quick look.
> 
> OK, thanks.
> However, I can reproduce the hang now with Tomcat 7 on Java 7. Although I
> do not get a exception, I get a short hang and a warning: "The executor
> associated with thread pool [http-bio-8080] has not fully shutdown. Some
> application threads may still be running." After that, Tomcat closed.
> I do not get this with Tomcat 8.
> 
> My reaction also would have been to just remove the dispose() in the
> Tomcat 7 example since it is unlikely that the examples application is
> reloaded many times on a Tomcat run and creates too much Graphics2D
> objects that the GC does not dispose. But of course, I have nothing against a
> better solution if you find one. :)

OK, that was not the full story:

I can reproduce the short hang (and the warning) on Tomcat 8 with BIO connector, but not with NIO or APR...


Regards,
Konstantin Preißer


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


RE: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Konstantin Preißer <kp...@apache.org>.
Hi Mark,

> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Thursday, October 17, 2013 1:10 PM
> To: Tomcat Developers List
> Subject: Re: svn commit: r1533035 -
> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> INF/classes/websocket/drawboard/Room.java
> 
> On 17/10/2013 11:53, Mark Thomas wrote:
> > On 17/10/2013 11:50, Konstantin Preißer wrote:
> >> Hi Mark,
> >>
> >>> -----Original Message-----
> >>> From: Mark Thomas [mailto:markt@apache.org]
> >>> Sent: Thursday, October 17, 2013 12:49 PM
> >>> To: Tomcat Developers List
> >>> Subject: Re: svn commit: r1533035 -
> >>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> >>> INF/classes/websocket/drawboard/Room.java
> >>>
> >>> On 17/10/2013 11:39, Konstantin Kolinko wrote:
> >>>> 2013/10/17  <ma...@apache.org>:
> >>>>> Author: markt
> >>>>> Date: Thu Oct 17 10:32:21 2013
> >>>>> New Revision: 1533035
> >>>>>
> >>>>> URL: http://svn.apache.org/r1533035
> >>>>> Log:
> >>>>> Avoid hangs on shutdown
> >>>>>
> >>>>> Modified:
> >>>>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> >>> INF/classes/websocket/drawboard/Room.java
> >>>>>
> >>>>
> >>>> I expect this to
> >>>> a) fail when running with a security manager
> >>>> b) cause a memory leak when examples app is reloaded, as you will get
> >>>> a new instance of ShutdownDetection class in webapp's classloader
> and
> >>>> new instance of shutdown hook.
> >>>
> >>> I'm open to better suggestions. Another option I considered was just
> >>> removing the call to roomGraphics.dispose(); and letting GC take care of
> >>> things.
> >>>
> >>> Alternatively, we could provide some form of global flag.
> >>>
> >>> I think I prefer the global flag that indicates that a shutdown is in
> >>> process. I can think of several other places where such a flag would
> >>> have been useful and we can expose it through a custom servlet context
> >>> attribute such as
> "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
> >>>
> >>> I'll start looking at the global flag option. Meanwhile, any suggestions
> >>> on how to improve the fix or an alternative fix welcome.
> >>
> >> Can you give me some insight of why Grahpics2D.dispose() may cause a
> hang on shutdown? I have never seen .dispose() causing a hang, at least not
> on Windows.
> >> If it hangs, might this be a result of different threads using the Grahpics
> object?
> >
> > Clean 7.0.x build
> > catalina.bat start
> > CTRL-C in the Tomcat Window
> >
> > The result is an exception written to stderr (I assume err rather than
> > out) and Tomcat fails to stop. The exception is triggered by AWT trying
> > to register a shutdown hook after the shutdown process has started.
> 
> Ah. More info. It only occurs with Java 6.
> 
> We could just classify this as a JVM bug and more on. That said, I think
> some changes to the init code could probably avoid this in Java 6 as
> well. I'll take a quick look.

OK, thanks.
However, I can reproduce the hang now with Tomcat 7 on Java 7. Although I do not get a exception, I get a short hang and a warning: "The executor associated with thread pool [http-bio-8080] has not fully shutdown. Some application threads may still be running." After that, Tomcat closed.
I do not get this with Tomcat 8.

My reaction also would have been to just remove the dispose() in the Tomcat 7 example since it is unlikely that the examples application is reloaded many times on a Tomcat run and creates too much Graphics2D objects that the GC does not dispose. But of course, I have nothing against a better solution if you find one. :)


Regards,
Konstantin Preißer




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2013 11:53, Mark Thomas wrote:
> On 17/10/2013 11:50, Konstantin Preißer wrote:
>> Hi Mark,
>>
>>> -----Original Message-----
>>> From: Mark Thomas [mailto:markt@apache.org]
>>> Sent: Thursday, October 17, 2013 12:49 PM
>>> To: Tomcat Developers List
>>> Subject: Re: svn commit: r1533035 -
>>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>>> INF/classes/websocket/drawboard/Room.java
>>>
>>> On 17/10/2013 11:39, Konstantin Kolinko wrote:
>>>> 2013/10/17  <ma...@apache.org>:
>>>>> Author: markt
>>>>> Date: Thu Oct 17 10:32:21 2013
>>>>> New Revision: 1533035
>>>>>
>>>>> URL: http://svn.apache.org/r1533035
>>>>> Log:
>>>>> Avoid hangs on shutdown
>>>>>
>>>>> Modified:
>>>>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>>> INF/classes/websocket/drawboard/Room.java
>>>>>
>>>>
>>>> I expect this to
>>>> a) fail when running with a security manager
>>>> b) cause a memory leak when examples app is reloaded, as you will get
>>>> a new instance of ShutdownDetection class in webapp's classloader and
>>>> new instance of shutdown hook.
>>>
>>> I'm open to better suggestions. Another option I considered was just
>>> removing the call to roomGraphics.dispose(); and letting GC take care of
>>> things.
>>>
>>> Alternatively, we could provide some form of global flag.
>>>
>>> I think I prefer the global flag that indicates that a shutdown is in
>>> process. I can think of several other places where such a flag would
>>> have been useful and we can expose it through a custom servlet context
>>> attribute such as "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
>>>
>>> I'll start looking at the global flag option. Meanwhile, any suggestions
>>> on how to improve the fix or an alternative fix welcome.
>>
>> Can you give me some insight of why Grahpics2D.dispose() may cause a hang on shutdown? I have never seen .dispose() causing a hang, at least not on Windows.
>> If it hangs, might this be a result of different threads using the Grahpics object?
> 
> Clean 7.0.x build
> catalina.bat start
> CTRL-C in the Tomcat Window
> 
> The result is an exception written to stderr (I assume err rather than
> out) and Tomcat fails to stop. The exception is triggered by AWT trying
> to register a shutdown hook after the shutdown process has started.

Ah. More info. It only occurs with Java 6.

We could just classify this as a JVM bug and more on. That said, I think
some changes to the init code could probably avoid this in Java 6 as
well. I'll take a quick look.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2013 11:50, Konstantin Preißer wrote:
> Hi Mark,
> 
>> -----Original Message-----
>> From: Mark Thomas [mailto:markt@apache.org]
>> Sent: Thursday, October 17, 2013 12:49 PM
>> To: Tomcat Developers List
>> Subject: Re: svn commit: r1533035 -
>> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>> INF/classes/websocket/drawboard/Room.java
>>
>> On 17/10/2013 11:39, Konstantin Kolinko wrote:
>>> 2013/10/17  <ma...@apache.org>:
>>>> Author: markt
>>>> Date: Thu Oct 17 10:32:21 2013
>>>> New Revision: 1533035
>>>>
>>>> URL: http://svn.apache.org/r1533035
>>>> Log:
>>>> Avoid hangs on shutdown
>>>>
>>>> Modified:
>>>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
>> INF/classes/websocket/drawboard/Room.java
>>>>
>>>
>>> I expect this to
>>> a) fail when running with a security manager
>>> b) cause a memory leak when examples app is reloaded, as you will get
>>> a new instance of ShutdownDetection class in webapp's classloader and
>>> new instance of shutdown hook.
>>
>> I'm open to better suggestions. Another option I considered was just
>> removing the call to roomGraphics.dispose(); and letting GC take care of
>> things.
>>
>> Alternatively, we could provide some form of global flag.
>>
>> I think I prefer the global flag that indicates that a shutdown is in
>> process. I can think of several other places where such a flag would
>> have been useful and we can expose it through a custom servlet context
>> attribute such as "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
>>
>> I'll start looking at the global flag option. Meanwhile, any suggestions
>> on how to improve the fix or an alternative fix welcome.
> 
> Can you give me some insight of why Grahpics2D.dispose() may cause a hang on shutdown? I have never seen .dispose() causing a hang, at least not on Windows.
> If it hangs, might this be a result of different threads using the Grahpics object?

Clean 7.0.x build
catalina.bat start
CTRL-C in the Tomcat Window

The result is an exception written to stderr (I assume err rather than
out) and Tomcat fails to stop. The exception is triggered by AWT trying
to register a shutdown hook after the shutdown process has started.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


RE: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Konstantin Preißer <kp...@apache.org>.
Hi Mark,

> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Thursday, October 17, 2013 12:49 PM
> To: Tomcat Developers List
> Subject: Re: svn commit: r1533035 -
> /tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> INF/classes/websocket/drawboard/Room.java
> 
> On 17/10/2013 11:39, Konstantin Kolinko wrote:
> > 2013/10/17  <ma...@apache.org>:
> >> Author: markt
> >> Date: Thu Oct 17 10:32:21 2013
> >> New Revision: 1533035
> >>
> >> URL: http://svn.apache.org/r1533035
> >> Log:
> >> Avoid hangs on shutdown
> >>
> >> Modified:
> >>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-
> INF/classes/websocket/drawboard/Room.java
> >>
> >
> > I expect this to
> > a) fail when running with a security manager
> > b) cause a memory leak when examples app is reloaded, as you will get
> > a new instance of ShutdownDetection class in webapp's classloader and
> > new instance of shutdown hook.
> 
> I'm open to better suggestions. Another option I considered was just
> removing the call to roomGraphics.dispose(); and letting GC take care of
> things.
> 
> Alternatively, we could provide some form of global flag.
> 
> I think I prefer the global flag that indicates that a shutdown is in
> process. I can think of several other places where such a flag would
> have been useful and we can expose it through a custom servlet context
> attribute such as "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".
> 
> I'll start looking at the global flag option. Meanwhile, any suggestions
> on how to improve the fix or an alternative fix welcome.

Can you give me some insight of why Grahpics2D.dispose() may cause a hang on shutdown? I have never seen .dispose() causing a hang, at least not on Windows.
If it hangs, might this be a result of different threads using the Grahpics object?


Regards,
Konstantin Preißer


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2013 11:39, Konstantin Kolinko wrote:
> 2013/10/17  <ma...@apache.org>:
>> Author: markt
>> Date: Thu Oct 17 10:32:21 2013
>> New Revision: 1533035
>>
>> URL: http://svn.apache.org/r1533035
>> Log:
>> Avoid hangs on shutdown
>>
>> Modified:
>>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
>>
> 
> I expect this to
> a) fail when running with a security manager
> b) cause a memory leak when examples app is reloaded, as you will get
> a new instance of ShutdownDetection class in webapp's classloader and
> new instance of shutdown hook.

I'm open to better suggestions. Another option I considered was just
removing the call to roomGraphics.dispose(); and letting GC take care of
things.

Alternatively, we could provide some form of global flag.

I think I prefer the global flag that indicates that a shutdown is in
process. I can think of several other places where such a flag would
have been useful and we can expose it through a custom servlet context
attribute such as "org.apache.tomcat.JVM_SHUTDOWN_IN_PROGRESS".

I'll start looking at the global flag option. Meanwhile, any suggestions
on how to improve the fix or an alternative fix welcome.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1533035 - /tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/10/17  <ma...@apache.org>:
> Author: markt
> Date: Thu Oct 17 10:32:21 2013
> New Revision: 1533035
>
> URL: http://svn.apache.org/r1533035
> Log:
> Avoid hangs on shutdown
>
> Modified:
>     tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
>

I expect this to
a) fail when running with a security manager
b) cause a memory leak when examples app is reloaded, as you will get
a new instance of ShutdownDetection class in webapp's classloader and
new instance of shutdown hook.


> Modified: tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
> URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java?rev=1533035&r1=1533034&r2=1533035&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java (original)
> +++ tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java Thu Oct 17 10:32:21 2013
> @@ -316,7 +316,9 @@ public final class Room {
>              public void run() {
>                  closed = true;
>                  drawmessageBroadcastTimer.cancel();
> -                roomGraphics.dispose();
> +                if (!ShutdownDetection.hasShutdownStarted()) {
> +                    roomGraphics.dispose();
> +                }
>              }
>          });
>      }
> @@ -412,4 +414,23 @@ public final class Room {
>              client.sendMessage(new StringWebsocketMessage(completeMsg));
>          }
>      }
> +
> +
> +    static {
> +        Runtime.getRuntime().addShutdownHook(new ShutdownDetection());
> +    }
> +
> +
> +    private static class ShutdownDetection extends Thread {
> +        private static volatile boolean shutdownStarted = false;
> +
> +        private static boolean hasShutdownStarted() {
> +            return shutdownStarted;
> +        }
> +
> +        @Override
> +        public void run() {
> +            shutdownStarted = true;
> +        }
> +    }
>  }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org