I have a very basic question. When i use any Swing components inside my Servlet, after the execution the Tomcat server gets shut down. Whereas if i use the components inside applet and then use in the Servlet the server works fine. Can anybody explain me why does it behave like that?
Here is the code which caused the server to shutdown.
and it will work fine. now the question is why? think on this, still if you have doubt get back here!
-Saaaaaaaaaaaachin.
dinesh Venkatesan
Ranch Hand
Joined: Oct 12, 2006
Posts: 134
posted
0
Thanks Sachin! Thanks for pointing out that mistake.
dinesh Venkatesan
Ranch Hand
Joined: Oct 12, 2006
Posts: 134
posted
0
Hi Sachin,
I have commented that line to avoid shutting down. But when i shut down the server properly, the server is not shutting down and throws an Exception that FAILED TO SHUTDOWN and gets hung.
Originally posted by Sachin Dimble: .. Just comment out the testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); and it will work fine....
Sachin Dimble, If you're not familiar with servlets or don't understand the issue that the original poster is having trouble with, please say so before trying to answer their question. Wrong or misleading answers are worse than no answer at all.
Sachin Dimble
Ranch Hand
Joined: Dec 07, 2005
Posts: 100
posted
0
Hey Ben cool! I know it's not possible to stick swing or awt components on servlets but if try to do same it will work but logicaly it's incorrect as these components never get delivered to client side, they are running under server jvm as an seperate frame, now if i close this frame which will lead to System.exit will kill the container jvm......shut down tomact....! Dinesh's problem was why tomcat gets shut down if he closed swing application. I was letting him think about above concept.
still if Dinesh gets mislead because of my post......I am realy SORRY.
Good point. System.exit is something that should never be called from within a web app.
Thanks for helping out.
Jeroen T Wenting
Ranch Hand
Joined: Apr 21, 2006
Posts: 1847
posted
0
and the reason the appserver doesn't shut down when you don't call it is that the Swing stuff will have started an event dispatcher thread which never gets killed.
As Ben says, NEVER mix Swing (or AWT, or SWT) with serverside components (Servlets, JSP, EJB, webservices, etc.). You may get lucky and get something that appears to work (especially if you only use non-visual elements of the APIs) but you're inviting trouble.
42
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.