More on thread pool MBean...what am I doing wrong?
yair.zaslavsky May 30, 2006 10:39 AMGood day.
I deployed the EJB3 trailblazer (JBoss 4.04 RC1) including the calculator MBean and managed to write a client that activates the calculator.
Now, I decided to take one step futher. In my tester class i wrote a static class called MyTask that implements Runnable and Serializable and looks like this:
public static class MyTask implements Runnable, Serializable {
private static final long serialVersionUID = -1575628286339248259L;
public void run()
{
System.out.println("hello!");
}
}
I then wrote the following code to get a thread pool (I found there are two thread pools by browsing with JBoss JMX-Console)
Object o = ctx.lookup("jmx/invoker/RMIAdaptor");
MBeanServerConnection mbsc = (MBeanServerConnection)o;
ObjectName objName = new ObjectName("jboss.system:service=ThreadPool");
if (mbsc.isRegistered(objName))
{
ObjectInstance objInstance = mbsc.getObjectInstance(objName);
if (objInstance != null)
{
System.out.println("got object instance");
System.out.println(objInstance.getClassName());
System.out.println(objInstance.getObjectName());
o = MBeanServerInvocationHandler.newProxyInstance(mbsc,
objName,ThreadPool.class,false);
if (o != null)
{
System.out.println("created proxy!");
ThreadPool threadPool = (ThreadPool)o;
threadPool.run(new MyTask());
}
}
}
I get the following exception:
java.lang.IllegalStateException: getArguments failed
at org.jboss.invocation.MarshalledInvocation.getArguments(MarshalledInvocation.java:513)
at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:235)
at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
.....
My question is - what am I doing wrong here? How can I use the thread pool to execute one task from the client side? is this because the client is not running on the same VM ?