0 Replies Latest reply on May 31, 2006 4:12 AM by Yair Zaslavsky

    More on using the thread pool - some progress and a question

    Yair Zaslavsky Newbie

      Good day,
      I managed to created an MBean that creates an instance of the thread pool and uses it.
      Here is the code:

      @Service (objectName="trail:service=TestThreadPool")
      @Management(TestThreadPool.class)
      @Depends ("jboss.system:service=ThreadPool")
      public class TestThreadPoolMBean implements TestThreadPool {

      static public class MyTask implements Runnable
      {
      public void run()
      {
      try
      {
      System.out.println("hello world!!!!!!");
      FileOutputStream fos = new FileOutputStream("c:\bla.txt");
      fos.write("hello world!".getBytes());
      fos.close();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }
      }

      ThreadPool pool;


      public int add(int a,int b)
      {
      return a+b;
      }


      public void doSomething()
      {
      pool.run(new MyTask());

      }


      public void create() throws Exception {
      // TODO Auto-generated method stub


      pool = new BasicThreadPool("MyPool");

      /* //commented out text
      try
      {
      MBeanServer server = MBeanServerLocator.locate();
      pool = (ThreadPool) MBeanProxyExt.create(
      ThreadPool.class,
      "jboss.system:service=ThreadPool",
      server);

      }
      catch (Exception e)
      {
      e.printStackTrace();
      throw e;
      }
      */ //end of commented out text



      }


      public void destroy() throws Exception {}


      public void stop() throws Exception {}


      public void start() throws Exception {}

      }

      As you can see, at the "create method" i create an instance of the BasicPool class. However, is there a away I can use the this service using lookup of the service? (you can see i tried something out in the commented code, but it doesnt work)

      Thanks alot

      Yair