Shouldn't the classloader come from the command rather than the pool?

--
Jeremy


[EMAIL PROTECTED] wrote:
Author: djencks
Date: Tue Feb  1 11:01:15 2005
New Revision: 149431

URL: http://svn.apache.org/viewcvs?view=rev&rev=149431
Log:
GERONIMO-562.  Thread pool assigns classloader when it creates a thread.  If 
the classloader the thread pool gets includes the naming stuff, our 
javaURLContextFactory can be loaded by one of these threads

Modified:
    
geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java
    
geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java
    
geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java
    
geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java

Modified: geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java?view=diff&r1=149430&r2=149431
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java (original)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java Tue Feb 1 11:01:15 2005
@@ -18,11 +18,9 @@
package org.apache.geronimo.pool;
import EDU.oswego.cs.dl.util.concurrent.Executor;
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
@@ -34,72 +32,45 @@
*/
public class ThreadPool implements Executor, GBeanLifecycle {
- static private final Log log = LogFactory.getLog(ThreadPool.class);
-
private PooledExecutor executor;
- private long keepAliveTime;
- private int poolSize;
- private String poolName;
private int nextWorkerID = 0;
- public long getKeepAliveTime() {
- return keepAliveTime;
- }
-
- public void setKeepAliveTime(long keepAliveTime) {
- this.keepAliveTime = keepAliveTime;
- }
-
- public int getPoolSize() {
- return poolSize;
- }
+ public ThreadPool(final int poolSize, final String poolName, final long keepAliveTime, final ClassLoader classLoader) {
+ PooledExecutor p = new PooledExecutor(new LinkedQueue(), poolSize);
+ p.setKeepAliveTime(keepAliveTime);
+ p.setMinimumPoolSize(poolSize);
+ p.setThreadFactory(new ThreadFactory() {
+ public Thread newThread(Runnable arg0) {
+ Thread thread = new Thread(arg0, poolName + " " + getNextWorkerID());
+ thread.setContextClassLoader(classLoader);
+ return thread;
+ }
+ });
- public void setPoolSize(int poolSize) {
- this.poolSize = poolSize;
+ executor = p;
}
- public String getPoolName() {
- return poolName;
- }
public void execute(Runnable command) throws InterruptedException {
executor.execute(command);
}
- public void setPoolName(String poolName) {
- this.poolName = poolName;
- }
-
- private int getNextWorkerID() {
+ private synchronized int getNextWorkerID() {
return nextWorkerID++;
}
public void doStart() throws WaitingException, Exception {
- PooledExecutor p = new PooledExecutor(new LinkedQueue(), poolSize);
- p.setKeepAliveTime(keepAliveTime);
- p.setMinimumPoolSize(poolSize);
- p.setThreadFactory(new ThreadFactory() {
- public Thread newThread(Runnable arg0) {
- return new Thread(arg0, poolName + " " + getNextWorkerID());
- }
- });
-
- executor = p;
-
- log.info("Thread pool " + poolName + " started");
}
public void doStop() throws WaitingException, Exception {
executor.shutdownNow();
- log.info("Thread pool " + poolName + " stopped");
}
public void doFail() {
try {
doStop();
} catch (Exception e) {
- log.error("Failed to shutdown", e);
}
}
@@ -108,11 +79,15 @@
static {
GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(ThreadPool.class);
- infoFactory.addAttribute("keepAliveTime", long.class, true);
infoFactory.addAttribute("poolSize", int.class, true);
infoFactory.addAttribute("poolName", String.class, true);
+ infoFactory.addAttribute("keepAliveTime", long.class, true);
+
+ infoFactory.addAttribute("classLoader", ClassLoader.class, false);
infoFactory.addInterface(Executor.class);
+
+ infoFactory.setConstructor(new String[] {"poolSize", "poolName", "keepAliveTime", "classLoader"});
GBEAN_INFO = infoFactory.getBeanInfo();
}


Modified: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java?view=diff&r1=149430&r2=149431
==============================================================================
--- geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java (original)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java Tue Feb 1 11:01:15 2005
@@ -17,7 +17,12 @@
package org.apache.geronimo.naming.java;
+import java.util.Properties;
+import java.util.Iterator;
+import java.util.Map;
import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.core.service.Invocation;
@@ -38,6 +43,8 @@
* @param compContext the component's JNDI Context
*/
public ComponentContextInterceptor(Interceptor next, Context compContext) {
+ assert next != null;
+ assert compContext != null;
this.next = next;
this.compContext = compContext;
}


Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java?view=diff&r1=149430&r2=149431
==============================================================================
--- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java (original)
+++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java Tue Feb 1 11:01:15 2005
@@ -42,8 +42,7 @@
private static final String createSequenceSQL = "create sequence timertasks_seq";
private static final String createTableSQLWithSequence = "create table timertasks (id long primary key, serverid varchar(256) not null, timerkey varchar(256) not null, userid varchar(4096), userinfo varchar(4096), firsttime long not null, period long, atfixedrate boolean not null)";
- private static final String createTableSQLWithIdentity =
-"create table timertasks (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), serverid varchar(256) not null, timerkey varchar(256) not null, userid varchar(4096), userinfo varchar(4096), firsttime NUMERIC(18,0) not null, period NUMERIC(18, 0), atfixedrate CHAR(1))";
+ private static final String createTableSQLWithIdentity = "create table timertasks (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), serverid varchar(256) not null, timerkey varchar(256) not null, userid varchar(4096), userinfo varchar(4096), firsttime NUMERIC(18,0) not null, period NUMERIC(18, 0), atfixedrate CHAR(1))";
private static final String sequenceSQL = "select timertasks_seq.nextval";
private static final String identitySQL = "values IDENTITY_VAL_LOCAL()";
private static final String insertSQLWithSequence = "insert into timertasks (id, serverid, timerkey, userid, userinfo, firsttime, period, atfixedrate) values (?, ?, ?, ?, ?, ?, ?, ?)";


Modified: geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java?view=diff&r1=149430&r2=149431
==============================================================================
--- geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java (original)
+++ geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java Tue Feb 1 11:01:15 2005
@@ -55,11 +55,7 @@
protected void setUp() throws Exception {
userTaskFactory = new MockUserTaskFactory();
- threadPool = new ThreadPool();
- threadPool.setPoolSize(30);
- threadPool.setKeepAliveTime(10000);
- threadPool.setPoolName("TestPool");
- threadPool.doStart();
+ threadPool = new ThreadPool(30, "TestPool", 10000, this.getClass().getClassLoader());
WorkerPersistence workerPersistence = new VMWorkerPersistence();
timer = new ThreadPooledTimer(executableWorkFactory, workerPersistence, threadPool, transactionContextManager);
timer.doStart();






Reply via email to