[jboss-user] [JCA/JBoss] - Re: 4.2.2.GA IdleRemover thread inserted into my thread grou

guy_rouillier do-not-reply at jboss.com
Wed Jul 9 04:11:17 EDT 2008


Vicky, thanks for the reply.  I finally have a reproducible test case.  I just spent two hours packaging it up and providing a read.me, but now it looks like I'm not allowed to upload a file here.

I can get this to happen using either an hsql or an Oracle datasource.  I'm using no-tx-datasource with an idle timeout specified.  As I say in the read.me, this problem occurs if only one no-tx-datasource is deployed.  I suppose I'll include the code for the EJB below.  When this is executed, the do loop terminated with "while (threadCt > 0)" never ends.

If there is some way for me to upload a file, let me know.  Thanks.


  | package guyr;
  | 
  | import java.sql.*;
  | import javax.sql.*;
  | import javax.naming.*;
  | import javax.annotation.*;
  | import javax.ejb.*;
  | import org.apache.log4j.Logger;
  | 
  | @Stateless(name = "guyr/TGroup")
  | 
  | public class TGroupBean implements TGroup
  |    {
  |    private final Logger log = Logger.getLogger(getClass().getName());
  |    private final int MAX_THREADS = 1;
  | 
  |    // For HSQL 
  | 
  |    // @Resource(mappedName="java:/hsqlDB")
  |    // private javax.sql.DataSource ds;
  |    //
  |    // String aSql = "select 'hsql'                          " +
  |    //               "from information_schema.system_tables  " +
  |    //               "where table_name = 'SYSTEM_TABLES'     " ;
  | 
  |    // For Oracle
  | 
  |       @Resource(mappedName="java:/rumbaDB")
  |       private javax.sql.DataSource ds;
  | 
  |       String aSql = "select 'oracle'                        " +
  |                     "from dual                              " ;
  | 
  |    private class TData extends Thread
  |       {
  |       // Doesn't work if resource is inside this thread class
  | 
  |       public TData(ThreadGroup tg, String aThreadName)
  |          {
  |          super(tg, aThreadName);
  |          } // end constructor
  | 
  |       public void run()
  |          {
  |          log.info("Thread " + this.getName() + " started");
  | 
  |          Connection c = null;
  |          Statement s = null;
  |          ResultSet r = null;
  | 
  | 
  |          try
  |             {
  |             c = ds.getConnection();
  |             // c.setAutoCommit(false);
  |             // c = ((DataSource)(new InitialContext()).lookup("java:/DefaultDS")).getConnection();
  |             s = c.createStatement();
  |             r = s.executeQuery(aSql);
  | 
  |             if ((r != null) && (r.next()))
  |                {
  |                log.info("Thread " + this.getName() + " result: " + r.getString(1));
  |                } // end if
  | 
  |             // c.commit();
  |             } // end try
  |          catch (Exception e)
  |             {
  |             log.error("Thread " + this.getName() + " exception: ", e);
  |             // try
  |             //    {
  |             //    c.rollback();
  |             //    } // end try
  |             // catch (Exception ne)
  |             //    {
  |             //    log.error("Thread " + this.getName() + " exception: ", ne);
  |             //    } // end catch
  |             } // end catch
  |          finally
  |             {
  |             if (r != null)
  |                {
  |                try
  |                   {
  |                   r.close();
  |                   } // end try
  |                catch (Exception e)
  |                   {
  |                   log.error("Thread " + this.getName() + " exception: ", e);
  |                   } // end catch
  |                } // end if
  | 
  |             if (s != null)
  |                {
  |                try
  |                   {
  |                   s.close();
  |                   } // end try
  |                catch (Exception e)
  |                   {
  |                   log.error("Thread " + this.getName() + " exception: ", e);
  |                   } // end catch
  |                } // end if
  | 
  |             if (c != null)
  |                {
  |                try
  |                   {
  |                   // c.setAutoCommit(true);
  |                   c.close();
  |                   } // end try
  |                catch (Exception e)
  |                   {
  |                   log.error("Thread " + this.getName() + " exception: ", e);
  |                   } // end catch
  |                } // end if
  |             } // end finally
  |          } // end run
  |       } // end class TData
  | 
  |    public void run()
  |       {
  |       log.info("TGroupBean.run() started");
  | 
  |       try
  |          {
  |          ThreadGroup tgTest = new ThreadGroup("TEST_THREADGROUP");
  | 
  |          for (int i = 0; i < MAX_THREADS; i++)
  |             {
  |             TData td = new TData(tgTest, "THREAD " + i);
  |             td.start();
  |             } // end for
  | 
  |          int threadCt = 0;
  | 
  |          do
  |             {
  |             Thread.sleep(2000);
  | 
  |             Thread[] activeThreads = new Thread[MAX_THREADS + 1];
  |             threadCt = tgTest.enumerate(activeThreads);
  | 
  |             for (int i = 0; i < threadCt; i++)
  |                {
  |                log.info("ThreadGroup " + tgTest.getName() + " thread " + i + " : " +
  |                         activeThreads.getName());
  |                }
  |             } while (threadCt > 0); // end do
  |          } // end try
  |       catch (Exception e)
  |          {
  |          log.error("Exception caught: " + e.getMessage());
  |          } // end catch
  | 
  |       log.info("TGroupBean.run() ended");
  |       } // end run
  |    } // end class TGroupBean
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4163219#4163219

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4163219



More information about the jboss-user mailing list