views:

83

answers:

2

I have a Swing runnable app which updates messages, then I have a Java servlet that gets messages from Paypal IPN (Instant Payment Notification), when the servlet starts up, in the init(), I starts the Swing runnable app which opens a desktop window, but 30 minutes later an error in the Swing caused the servlet to stop, how can that happen ? Because the runnable is running on it's own thread, servlet started that thread, why an error in that thread will cause the servlet to stop ?

public class License_Manager extends JPanel implements Runnable
{
  License_Manager()
  {
    Do_GUI();
    ...
    start();
  }

  public static void main(String[] args)
  {
    // Schedule a job for the event-dispatching thread : creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { Create_And_Show_GUI(); } });
  }
}

public class PayPal_Servlet extends HttpServlet
{
  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
    License_Manager.main(null);
  }

  protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
  {
  }
}

And besides the error don't even have anything to do with my code, it looks like this :

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 17 >= 0
    at java.util.Vector.elementAt(Vector.java:427)
    at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:70)
    at javax.swing.plaf.basic.BasicListUI.paintCell(BasicListUI.java:191)
    at javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:304)
    at javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:227)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
    at javax.swing.JComponent.paintComponent(JComponent.java:763)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JViewport.paint(JViewport.java:747)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Edit :

Thanks for all the replies, it seems starting a thread in init() is a bad idea, my original idea was, my Swing GUI app processes all the messages the servlet gets and writes to a folder and I can see the GUI working on the screen while the servlet gets the messages at the back end, they are related, so I run those two processes at the same time and starting the servlet will automatically starts the GUI for me too in the init(), now I may start those 2 processes separately so that no matter what happens to the GUI, the servlet won't stop !

+1  A: 

Seems definitely wierd. Saw something similar on sun (now oracle) forums. No good answer on it till now. But may be you can get a clue as it seems the same problem Link http://72.5.124.102/thread.jspa?threadID=5339908&messageID=10469703

Fazal
Great catch !!! I definitely can learn from that !
Frank
+1  A: 

Sorry if I'm stating the obvious, but it looks like you have a JList in your GUI, and its backing model is being emptied while it's being painted. It expects at least 18 elements, and shows that there are 0. Is there somewhere that you're modified the contents of the list outside of the event dispatch thread?

Rob Heiser