1 2 Previous Next 16 Replies Latest reply on Apr 5, 2016 12:01 PM by tanvir

    Threading inside JBoss

    thehunt

      Hi all,

      I want to refer to something I could not find information about, after googling half an hour. Threading inside Jboss.

      As far as I know, it is not a best practice to create you own threads inside an application server, but instead you should ask from the server to do so for you. On the other hand, several apps I 've seen (a couple of mine I must admit) do so without any problem.

      So, my question comes down to this :
      I know we can assign different apps inside Jboss, to be server by different ThreadPools, but when we need to start our own threads what should we do?
      A. Create our own threads like : new Thread(runnable) ?
      B. Use JSE Executors ThreadPool ?
      C. Create a BasicThreadPool MBean for our app in Jboss and run our runnables on this pool?
      D. Other way I cannot imagine.

      If the correct answer is C, doesn't it tightly couples our application to Jboss?

      Btw during my search I came across this :
      http://www.coderanch.com/t/428370/JBoss/JBoss-Basic-ThreadPool

      A friend here is wondering, if using a JSE fixedThreadPool inside a .SAR
      is actually delegating to the basicThreadPool assigned to this .SAR. Which of course I guess doesn't happen.

      Thx in advance for any replies.



        • 1. Threading inside JBoss
          vijaysachin

          I am new to Jboss. Please tell me how to configure thread pool. I fedup by searching google from long time please me.

           

          I found a link http://community.jboss.org/wiki/ConfigBasicThreadPool  in this link they had not specfied which file I have to put those XML code.

           

          And also give some sample code how can I implement Thread Pool

          • 2. Threading inside JBoss
            alesj
            Please tell me how to configure thread pool. I fedup by searching google from long time please me.

            * http://lmgtfy.com/?q=jboss+thread+pool ... top item ;-)

            • 3. Threading inside JBoss
              vijaysachin

              Seen all the links man but cannot get proper Information. Please post some same example

              • 4. Threading inside JBoss
                alesj

                Please post some same example

                What kind of example?

                 

                The wiki goes into details explaining all sorts of config options.

                And the actual code is here: https://github.com/dmlloyd/jboss-threads

                While you can search the JBossAS config files for actual usage.

                • 5. Threading inside JBoss
                  jaikiran

                  Actually, you even got a detailed reply in this post here http://www.coderanch.com/t/528949/JBoss/configure-Thread-pool-JBOSS

                  • 6. Threading inside JBoss
                    vijaysachin

                    Actually, you even got a detailed reply in this post here http://www.coderanch.com/t/528949/JBoss/configure-Thread-pool-JBOSS

                    But the above link shows how to creates MDB pool.

                    But I need to know how can we creat normal Thread pool in jboss

                     

                    While googling I got to see this one link  http://community.jboss.org/wiki/ConfigBasicThreadPool

                    But below they had not specified which xml file I need to change. And also I need to know how can I use this Java code

                     

                    Configuration of a BasicThreadPool

                    The basic thread pool provides a simple thread pooling service

                    Example Configuration


                      <mbean code="org.jboss.util.threadpool.BasicThreadPool" name="jboss.jca:service=WorkManagerThreadPool">
                         <!-- The name that appears in thread names -->
                         <attribute name="Name">WorkManager</attribute>
                         <!-- The maximum amount of work in the queue -->
                         <attribute name="MaximumQueueSize">1024</attribute>
                         <!-- The maximum number of active threads -->
                         <attribute name="MaximumPoolSize">100</attribute>
                         <!-- How long to keep threads alive after their last work (default one minute) -->
                         <attribute name="KeepAliveTime">60000</attribute>
                      </mbean>
                    • 7. Threading inside JBoss
                      jaikiran

                      vijaysachin sachin wrote:

                       

                      Actually, you even got a detailed reply in this post here http://www.coderanch.com/t/528949/JBoss/configure-Thread-pool-JBOSS

                      But the above link shows how to creates MDB pool.

                      But I need to know how can we creat normal Thread pool in jboss

                      And how and where do you plan to use that thread pool?

                      • 8. Threading inside JBoss
                        vijaysachin

                        And how and where do you plan to use that thread pool?

                        My requirement is something different MDB pool can solve my requirement.

                        But I need to know like Connection pool, MDB pool how can I create Thread Pool in jboss.

                        Which xml files need to be changed?

                        • 9. Threading inside JBoss
                          peterj

                          I still do not understand why my answer does not solve your problem. You stated that when your MDB grabs a message off of the queue that it might take a long time for it to process the message and you do not want the other messages in the queue being ignored during that time. I told you that there are actually 15 (by default) MDB instances processing messages out of the queue and even showed you how you could increase that limit.

                           

                          If you pull a message off a queue and decide you need to fork a thread to process the message, then you are not thinking correctly. The whole purpose of a messaging system is so that you can process things asynchronously.

                           

                          Or was message processing by and MDB not your real requirement? If you get some other request, let's say from a web service, and that request will take a long time to process, then I suggest that you create another messaging queue and place the request on that queue and have an MDB do the processing. That is the whole purpose of messaging. Don't fight the Java EE architecture, and don't limit yourself to requirements that you don't really need. Instead, make use of the Java EE architecture.

                          • 10. Threading inside JBoss
                            mhvenkat

                            Hi Peter,

                             

                            I have same frustration as Vijay.  I would like to use JBoss threads programmatically in non-MDB cases. In a Web App, when I want to integrate with an external service, I would like to fork a thread to invoke the external http service.

                            Rather than using JDK concurrent util package, if I want to JBoss org.jboss.util.threadpool.BasicThreadPool for my custom logic how will I do it programmatically?

                            Sure I can add an entry in the conf\jboss-service.xml or jbossweb.sar\META-INF\jboss-beans.xml to define a custom worker thread pool

                            Now I in order to use this custom worker thread pool, I think we need to develop JMX MBean Proxy to invoke it.

                             

                            Can someone provide a code snippet to develop JBoss MBean and its Proxy that can invoked programmatically in an jboss web app ?

                             

                            Thanks

                            --Mahesh

                            • 11. Threading inside JBoss
                              mhvenkat

                              I think I finally have the answer on how to feed a runnable task to the BasicthreadPool.  Look at

                                 http://community.jboss.org/message/230378

                               

                              This post describes the configuration and code snippet which I have elaborated below ...

                               

                              Use JBossWorkManager.

                               

                              Implement a javax.resource.spi.work.Work; which extends Runnable interface and implement the run() method.

                               

                               

                              Mywork implements  Work {

                                   void run()  {

                                        // your main logic

                                  }

                               

                              }

                               

                              Get an instance of JBossWorkManager using the following code:

                               

                              WorkManager customWorkManager = null; // JBossWorkManager extends WorkManager

                              Work mywork = new MyWork();
                              try {
                                  MBeanServer server = MBeanServerLocator.locateJBoss();
                                  customWorkManager = (WorkManager) server.getAttribute(new ObjectName(
                                                                "custom.jca:service=CustomWorkManager"), "Instance");

                                   customWorkManager.getInstance().doWork(mywork);
                              } catch (MalformedObjectNameException e) {
                                            // TODO
                              } catch (Exception e) {
                                           // TODO
                              }

                                

                              Let me know if this works for you.


                              Thanks

                              --Mahesh

                              • 12. Re: Threading inside JBoss
                                spyhunter99

                                From the class that actual performs the work, how do you access context variables or objects that are necessary to do the work?

                                I was expecting something like,

                                 

                                customWorkManager.getInstance().doWork(mywork);           //this does the enqueue

                                 

                                then the work manager does the dequeue and handles the threading

                                 

                                void run()  {

                                          // your main logic

                                          Object j = //some code is needed to get stuff from the queue?

                                    }

                                • 13. Re: Threading inside JBoss
                                  spyhunter99

                                  Ahh never mind, I understand the way it works now. thanks for the post

                                  • 14. Re: Threading inside JBoss
                                    spyhunter99

                                    I'm using Jboss 6.1 and I keep getting instancenotfound exception on server.getAttribute. Should the thread pool be visible in the jmx console?

                                    In addition, the api seems to be different in jboss 6.1.

                                     

                                      customWorkManager.getInstance().doWork(mywork);

                                    doesn't exist

                                      customWorkManager.doWork(mywork);

                                    does

                                    1 2 Previous Next