Skip to Content
avatar image
Former Member

jndi lookup problem

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 24, 2006 at 03:12 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 25, 2006 at 08:43 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded