cancel
Showing results for 
Search instead for 
Did you mean: 

jndi lookup problem

Former Member
0 Kudos

I use jndi as temporary storage: first time when application runs it creates a thread and put it into jndi. next times application tries to find created thread in jndi - all is OK until i try to cast found object to my type.

class MyType implements Runnable{....}

in app:

Context ctx = null;

try {

Hashtable props = new Hashtable(1);

props.put("domain", "true");

ctx = new InitialContext(props);

Object found = ctx.lookup("jndiNameHere");

c = ((MyType ) found).getCounter(); // ClassCastException Here

} catch (NameNotFoundException e) {

MyType myType = new Scheduler();

try {

ctx.bind("jndiNameHere", myType );

} catch (NamingException e1) {

throw new ServletException(e);

}

myType .start();

} catch (Exception e) {

throw new ServletException(e);

}

the problem can be solved by making MyType Serializable:

class MyType implements Runnable, Serializable{....}

but in this case after jndi lookup i will have deSerialized object. This is not good for me - my thread (MyType) elters variable 'counter' and i want to get reference to the object with altered value.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Denis,

it´s not recommended to create your own threads in a container. Please tell more about your requirements, perhaps there is a smarter solution.

Regards

Sebastian

Former Member
0 Kudos

In general I want to create a scheduler - process which will start with the server and process some jobs.

Former Member
0 Kudos

Consider to use JMS (Java Message Service). You can put your jobs in a queue and a listener can process these jobs. This is the recommended solution to realize asynchronous communication.

I hope that helps a little bit. There are a lot of tutorials about JMS on the net (of course there are some pitfalls with SAP WAS, when you running in problems just ask here in the forum).

Regards

Sebastian

Message was edited by: Sebastian Voss

Former Member
0 Kudos

Denis,

Try this approach: <a href="/people/maksim.rashchynski/blog/2006/07/19/sdn-rss-feeds-spider-using-was-timeout-service">SDN RSS Feeds spider using WAS Timeout Service</a> by <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=pyouhggpqqi%3d">maksim Rashchynski</a>, btw our former collegue.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

P.S. Join the <a href="http://sdn.idizaai.be/sdn_world/sdn_world.html">SDN World</a>!

Answers (1)

Answers (1)

Former Member
0 Kudos

The main problem i faced - is to init queue of task only one time - when server starts. Starts/stop/redeploy of my app must not influence on tasks.

Former Member
0 Kudos

Denis,

The only "closest" match is to develop your application as WebAS service. However, even service can be stopped / started. Sure, you may access Timeout service from your own service, but I'm not sure how to define order of service startup...

VS

former_member182372
Active Contributor
0 Kudos

Denis, I will publish the blog about how to create WAS service and use TimeoutService inside this week.

Best regards, Maksim Rashchynski.