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

vickyk do-not-reply at jboss.com
Fri Jul 11 04:48:22 EDT 2008


Hi Guy ,

I have been able to determine the cause of this issue .

Here is the code which creates the IdleRemover thread 
public Object run()
  |          {
  |             Runnable runnable = new IdleRemoverRunnable();
  |             Thread removerThread = new Thread(runnable, "IdleRemover");
  |             removerThread.setDaemon(true);
  |             removerThread.start();
  |             return null;
  |          }
  | 
http://anonsvn.jboss.org/repos/jbossas/branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/IdleRemover.java

Now look at this one 
Thread removerThread = new Thread(runnable, "IdleRemover");

This is getting invoke through the application thread context and in your case the application thread falls in the TEST_THREADGROUP threadgroup .

If you look at the java docs you will read these things 

anonymous wrote : Allocates a new Thread object. This constructor has the same effect as Thread(null, target, name).

anonymous wrote : If group is null and there is a security manager, the group is determined by the security manager's getThreadGroup method. If group is null and there is not a security manager, or the security manager's getThreadGroup method returns null, the group is set to be the same ThreadGroup as the thread that is creating the new thread.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#Thread(java.lang.Runnable,%20java.lang.String)

This would explain why the IdleThread goes in the TEST_THREADGROUP .

The same can be viewed from listThreadDump() operations of the jboss.system:type=ServerInfo MBean .

Ideally the jboss generated Threads should go in the jboss ThreadGroup , I am going to make changes for that .

I am interested to know how  does this behavior creates an issues in your application .

btw , here is the jsp version of the problem .

<%@ page import="javax.xml.*,javax.sql.*,javax.naming.*,java.sql.*" %>
  | <%!
  | 	ThreadGroup tgroup = null ;
  | 	int counter = 0;
  | 	String aSql = "select 'hsql'                          " +
  | 
  |                     "from information_schema.system_tables  " +
  | 
  |                     "where table_name = 'SYSTEM_TABLES'     " ;
  | 
  | 
  | 	 private class TData extends Thread
  | 	 {
  | 		
  | 		public TData(ThreadGroup tg, String aThreadName)
  | 
  |          	{
  | 
  |          		super(tg, aThreadName);
  | 
  |          	} // e
  | 		
  | 		public TData(String aThreadName)
  | 
  |          	{
  | 
  |          		super(aThreadName);
  | 
  |          	} // e
  | 		public void run(){
  | 		try{
  | 		InitialContext context = new InitialContext();
  | 		DataSource ds = (DataSource)context.lookup("java:/hsqlDB");
  | 		Connection con = ds.getConnection();
  | 		Statement stmt = con.createStatement();
  | 
  |             	ResultSet rs = stmt.executeQuery(aSql);
  | 		while(rs.next())
  | 		System.out.println("--->"+rs.getString(1));
  | 		Thread.sleep(1000);
  | 		System.out.println("DOne");
  | 		}
  | 		catch(Exception e)
  | 		{
  | 		}
  | 		}
  | 	 }
  | %>
  | 
  | <%
  | 	
  | 	ThreadGroup tgTest = new ThreadGroup("TEST_THREADGROUP");
  | 	out.println("coutner is "+counter+"<br>");
  | 	if(counter == 0){
  | 		
  | 		tgroup = tgTest;
  | 	}
  | 
  | 	//v.add(tgTest);
  | 	for (int i = 0; i < 2; i++)
  | 
  |             {
  | 
  |             TData td = new TData(tgTest, "THREAD " + i);
  | 	    //TData td = new TData("THREAD " + i);
  | 
  |             td.start();
  | 
  |             }
  | 
  | 	Thread[] activeThreads = new Thread[10];		
  | 	int threadCt = tgTest.enumerate(activeThreads);
  | 
  | 	out.println(threadCt+"<br>");
  | 	out.println(tgTest.getParent()+"<br>");
  | 	for (int i = 0; i < threadCt; i++)
  | 
  |         {
  | 
  |         	out.println("ThreadGroup " + tgTest.getName() + " thread " + i + " : " +
  | 
  |                         activeThreads.getName()+"<br>");
  | 
  |         }
  | 	
  | 	out.println("First group count ::: "+tgroup.activeCount()+"<br>");
  | 	Thread[] activeList = new Thread[tgroup.activeCount()+1];
  | 	int threadCt1 = tgroup.enumerate(activeList);
  | 	for (int i = 0; i < threadCt1; i++)
  | 
  |         {
  | 		out.println(activeList.getName()+"<br>");
  | 	}	
  | 	counter = counter + 1;
  | 
  | %>


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

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



More information about the jboss-user mailing list