-
Timers in EJBs (4 messages)
- Posted by: Gerald Gutierrez
- Posted on: September 01 2000 04:03 EDT
The scenario is simple: a system, as part of its business logic, makes a request to something, and expects a response within 2 seconds (or minutes or days or whatever). If the response is not received, the system must alert an operator.
How do I implement this timer within the J2EE framework?
Threaded Messages (4)
- Timers in EJBs by Trond Arve Wasskog on September 01 2000 10:18 EDT
- Timers in EJBs by Dimitri Rakitine on September 04 2000 02:20 EDT
- Timers in EJBs by Dave Wolf on September 05 2000 14:14 EDT
- Timers in EJBs by Gene Chuang on September 06 2000 02:33 EDT
-
Timers in EJBs[ Go to top ]
- Posted by: Trond Arve Wasskog
- Posted on: September 01 2000 10:18 EDT
- in response to Gerald Gutierrez
Have you considered using a JMS service call? I think it is possible to specify a timeout for synchronous calls, which may be exactly what you are looking for. -
Timers in EJBs[ Go to top ]
- Posted by: Dimitri Rakitine
- Posted on: September 04 2000 02:20 EDT
- in response to Gerald Gutierrez
I do not this it has anything to do with J2EE. In your monitoring application you just implement timeout mechanism and use it to see if the application responds in a timely manner, for example:
TimedOp op = new CheckSomeFunction(...);
if(!op.do(2000) {
... alert operator here ...
}
abstract class TimedOp implements Runnable {
private boolean done = false;
...
public boolean do(timeout) throws InterruptedException {
boolean ok = false;
(new Thread(this)).start();
synchronized(this) {
if(done) {
ok = true;
} else {
wait(timeout);
ok = done;
}
}
return ok;
}
public void run() {
doStuff();
synchronized(this) {
done = true;
notify();
}
}
// to be implemented by the user
public abstract void doStuff();
}
-
Timers in EJBs[ Go to top ]
- Posted by: Dave Wolf
- Posted on: September 05 2000 14:14 EDT
- in response to Dimitri Rakitine
Note, use of thread synchornization is strictly forbidden in EJB. So you cannot use the above approach in a portable way. I reccomend a synchornous JMS call with a timeout.
Dave Wolf
Internet Applications Division
Sybase
-
Timers in EJBs[ Go to top ]
- Posted by: Gene Chuang
- Posted on: September 06 2000 02:33 EDT
- in response to Gerald Gutierrez
When you say "a system, as part of its business logic, makes a request to something, and expects a response within 2 seconds", who is making the asynchronous request? The client or an EJBean?
In either case, to make asynchronous requests and callbacks involving EJBs, you CANNOT use a timer! Plain EJBs are simply synchronous; to make EJBs asynchronous you either have to spice it up with JMS or use EJB 2.0 MessageBeans.
Gene Chuang
Teach the world... Join Kiko!