+ All Categories
Home > Documents > Weblogic Thread Pooling

Weblogic Thread Pooling

Date post: 14-Apr-2018
Category:
Upload: rosewinjohnrose
View: 476 times
Download: 0 times
Share this document with a friend

of 9

Transcript
  • 7/29/2019 Weblogic Thread Pooling

    1/9

    Weblogic thread pooling

    1. Introduction

    Thread pooling refers to a technique where a pool of worker threads are created and managed by the

    application. When a new job arrives, instead of creating a new thread to service it, it's queued by the thread-

    pool manager and dispatched later to one of the available worker threads. The thread-pool manager manages

    the number of active worker threads based on available resources as well as load considerations, adding new

    threads to the pool or freeing some worker threads in response to the number of outstanding requests. The

    primary goals of thread pooling are managing the number of active threads in the system and reducing the

    overhead of creating new threads by reusing threads from a pool. Please click on the below link to know more

    about thread pooling.

    http://java.sys-con.com/node/37241

    2. Thread pool types

    There are two ways of implementing thread pool for the web components like JSP, Servlet etc. and its

    associated classes develop your own thread pool library or leverage out of the box support from application

    servers like weblogic. Creating your own work managers, work queues, work listeners, work and itssynchronizations are so difficult and time consuming. This document outlines how a thread pool can be

    configured in weblogic and uses it in the programs.

    3. Weblogic Configurations

    As the first step, follow the below steps to configure the thread pool in weblogic which includes specifying the

    minimum thread count, maximum thread count etc. Screenshots are provided for each step for easy

    understanding

    1) Log into weblogic admin console

    2) Expand Environment from the left menu as in the below screenshot

    http://java.sys-con.com/node/37241http://java.sys-con.com/node/37241http://java.sys-con.com/node/37241
  • 7/29/2019 Weblogic Thread Pooling

    2/9

    3) Click on Work Managers link

  • 7/29/2019 Weblogic Thread Pooling

    3/9

    4) Click on Lock & Edit button from the left menu

    5) Click on New button

  • 7/29/2019 Weblogic Thread Pooling

    4/9

    6) Click on Next button

    7) Enterthe name for your work manager (eg: TestWorkManager) and click on Next button

  • 7/29/2019 Weblogic Thread Pooling

    5/9

    8) Select the weblogic instance/cluster where your application runs and click Finish

    9) Click on Activate Changes from the left top menu.

  • 7/29/2019 Weblogic Thread Pooling

    6/9

    10) Click on the work manager which is newly created

    11) You may configure minimum thread count, maximum thread count; total number of requests can be queued

    etc. here.

  • 7/29/2019 Weblogic Thread Pooling

    7/9

    4. Web.xml changes

    Next step is to specify the thread pool as a resource in the web.xml file as below. Its important to note that the

    work manager name and should match.

    wm/TestWorkManager

    commonj.work.WorkManager

    Container

    Shareable

    5. Use thread pool in the program

    Now that you have a thread pool configured in weblogic and can be used in the programs. Next step is to write

    a class which implements commonj.work.Work interface. The business logic should go inside run() method as

    shown below. An instance of this class represents a Work/Job/Task. In the below example, one instance of

    MyWork class can print the numbers in the provided color (eg-green)

    class MyWork implements Work{PrintWriter pw;

  • 7/29/2019 Weblogic Thread Pooling

    8/9

    String fontcolor;int count;public MyWork(PrintWriter pw, String fontcolor, int count){

    this.pw=pw;this.fontcolor = fontcolor;this.count= count;

    }public void run() {

    for(int i=0;i

  • 7/29/2019 Weblogic Thread Pooling

    9/9

    workItemList.add(workItem1);

    workItemList.add(workItem2);

    //Wai t th e main th read to fin is h al l th e th read s

    boolean finshed = workManager.waitForAll(workItemList, WorkManager.INDEFINITE);

    out.println("" +finshed + "");

    %>

    6. Resultant screen

    Note- The above configurations and program have been tested in weblogic 10.0.1 version. It should work

    similarly in other versions from 9.2 without any changes as per Oracle Inc.


Recommended