Thursday, September 29, 2011

WebLogic WorkManager for Multi-threading

WebLogic's WorkManager provides a self-tuned ThreadPool to enable Multi-Threading.

Define a WorkManager either in WLS console or in web.xml as below.

<resource-ref>
<res-ref-name>wm/MyWorkManager</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>


In weblogic-application.xml, you can configure the ThreadPool Size

  <work-manager>
<name>wm/MyWorkManager</name>
<max-threads-constraint>
<name>a</name>
<count>5</count>
</max-threads-constraint>
</work-manager>
<work-manager>


Java Code

        try {
InitialContext ic = new InitialContext();
WorkManager workManager = (WorkManager)ic.lookup("java:comp/env/wm/MyWorkManager");
List workItemList=new ArrayList();

for(int i=0;i<10;i++){
WorkItem workItem1 = startWorkItem(my,i,"OSMM");
workItemList.add(workItem1);
}



//run the work items in parallel; don't wait
//workManager.waitForAll(workItemList, WorkManager.IMMEDIATE);


    public WorkItem startWorkItem(WorkManager workManager, final int count, final String wmName) throws Exception{
WorkItem workItem10 = workManager.schedule(new Work() {
public void run() {
try {
System.out.println("Current Count ["+count+"] : wmName ["+wmName+"]ThreadName Is: "+Thread.currentThread().getName()+"##Priroty="+Thread.currentThread().getPriority());
} catch (Exception e) {
e.printStackTrace();
}
}

public void release() {
}

public boolean isDaemon() {
return false;
}
}); //End of Schedule
return workItem10;

}

PLSQL:Encryption Decryption DBMS_CRYPTO

set serveroutput on

DECLARE
LC$Source VARCHAR2(19) := 'Music is the best!';
LR$Source RAW(128) := utl_raw.cast_to_raw(LC$Source);
LR$Key RAW(128) := utl_raw.cast_to_raw('FrankZappa');
LR$Crypted RAW(2048);
LR$Decrypted RAW(2048);

BEGIN

dbms_output.put_line('Source string : ' || LC$Source);

LR$Crypted := dbms_crypto.encrypt(LR$Source,
dbms_crypto.des_cbc_pkcs5, LR$Key);

dbms_output.put_line('Encrypted raw : ' ||
RAWTOHEX(utl_raw.cast_to_raw(LR$Crypted)));

LR$Decrypted := dbms_crypto.decrypt(src => LR$Crypted,
typ => dbms_crypto.des_cbc_pkcs5, key => LR$Key);

dbms_output.put_line('Decrypted string : ' ||
utl_raw.cast_to_varchar2(LR$Decrypted));
END;
/