Saturday, May 14, 2011

Weblogic Work Manager

Using Work Managers to Optimize Scheduled Work
http://download.oracle.com/docs/cd/E14571_01/web.1111/e13701/self_tuned.htm#i1072698

Timer and Work Manager API (CommonJ) Programmer's Guide for Oracle WebLogic Server
http://download.oracle.com/docs/cd/E14571_01/web.1111/e13733/toc.htm

Tuning Message-Driven Beans
http://download.oracle.com/docs/cd/E14571_01/web.1111/e13814/mdbtuning.htm#i1134848

weblogic-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.2/weblogic-ejb-jar.xsd">
<!--weblogic-version:10.3.4-->
<wls:weblogic-enterprise-bean>
<wls:ejb-name>TestSesssionEJB</wls:ejb-name>
<wls:stateless-session-descriptor/>
<wls:run-as-principal-name>dave</wls:run-as-principal-name>
<wls:dispatch-policy>daveWM</wls:dispatch-policy>
</wls:weblogic-enterprise-bean>
<wls:weblogic-enterprise-bean>
<wls:ejb-name>SesssionJPA2EJB</wls:ejb-name>
<wls:stateless-session-descriptor/>
<wls:run-as-principal-name>dave</wls:run-as-principal-name>
</wls:weblogic-enterprise-bean>

<wls:work-manager>
<wls:name>daveWM</wls:name>

<wls:max-threads-constraint>
<wls:name>MaxThreadsCountFive</wls:name>
<wls:count>5</wls:count>
</wls:max-threads-constraint>
</wls:work-manager>


</wls:weblogic-ejb-jar>



TestSessionEJB
package dave;


import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.transaction.SystemException;

import org.apache.log4j.Logger;

import weblogic.javaee.TransactionTimeoutSeconds;
import weblogic.kernel.ExecuteThread;
import weblogic.transaction.Transaction;
import weblogic.transaction.TransactionHelper;
import weblogic.work.WorkManager;

/**
* Session Bean implementation class TestSesssionEJB
*/
@Stateless(mappedName = "TestSesssionEJB")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionTimeoutSeconds(1800)
public class TestSesssionEJB implements TestSesssionEJBRemote, TestSesssionEJBLocal {

static Logger logger = Logger.getLogger(TestSesssionEJB.class.getName());

/**
* Default constructor.
*/
public TestSesssionEJB() {
}



@Override
public String testWorkManager(int maxThreads) {

System.out.println("WorkManager: maxThreads" + maxThreads);

InitialContext ic = null;
try {
ic = new InitialContext();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

WorkManager wm = ((weblogic.work.ExecuteThread) Thread
.currentThread()).getWorkManager();
String wmName = wm.getName();
int queueDepth = wm.getQueueDepth();
String threadName = Thread.currentThread().getName();
StringBuilder sb = new StringBuilder();
sb.append("## [testWorkManager] executing in WM: " + wmName);
sb.append(" queueDepth=" + queueDepth);
sb.append(" currentThread=" + threadName);
System.out.println(sb);

try {
Thread.currentThread().sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return sb.toString() ;

}



}



Client log
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '17' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=1 currentThread=[ACTIVE] ExecuteThread: '17' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=2 currentThread=[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=1 currentThread=[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'
WorkManager: maxThreads20
## [testWorkManager] executing in WM: daveWM queueDepth=0 currentThread=[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'






AdminServer log
####<May 15, 2011 9:27:49 AM CEST> <Info> <WorkManager> <dave> <AdminServer> <ExecuteThread: '0' for queue: 'weblogic.socket.Muxer'> <<WLS Kernel>> <> <> <1305444469893> <BEA-002936> <maximum thread constraint MaxThreadsCountFive is reached> 
####<May 15, 2011 9:27:52 AM CEST> <Info> <WorkManager> <dave> <AdminServer> <ExecuteThread: '2' for queue: 'weblogic.socket.Muxer'> <<WLS Kernel>> <> <> <1305444472266> <BEA-002936> <maximum thread constraint MaxThreadsCountFive is reached>
####<May 15, 2011 9:27:54 AM CEST> <Info> <WorkManager> <dave> <AdminServer> <ExecuteThread: '2' for queue: 'weblogic.socket.Muxer'> <<WLS Kernel>> <> <> <1305444474651> <BEA-002936> <maximum thread constraint MaxThreadsCountFive is reached>
####<May 15, 2011 9:27:55 AM CEST> <Info> <WorkManager> <dave> <AdminServer> <ExecuteThread: '1' for queue: 'weblogic.socket.Muxer'> <<WLS Kernel>> <> <> <1305444475790> <BEA-002936> <maximum thread constraint MaxThreadsCountFive is reached>



WLS console - monitoring