I'm having a problem trying to integrate an OSGi bundle that implements a countdown in order to send a message in an specific time lapse. This is made by a runnable class, or thread.
The idea is the next; I've got bundle Sender
, bundle Receiver
and bundle Countdown
.
The Sender bundle sends a message after a time lapse, f.e: 5 seconds.
Sender ->Create message
Countdown -> Count to 5 s.
Receiver ->Receive the message after 5 s.
This is just a "metaphore" of my application, but well, I believe you got the idea.
The problem I'm experiencing is the next one: when the bundle Countdown
is running its 5 seconds countdown, the bundle Sender
stops working (it's OKAY, no problem here), but the bundle Receiver
also stops working. My idea was to implement the countdown in a separate bundle just to avoid other bundles to stop working, but I guess I was wrong.
So, my question is... how could I implement a countdown that doesn't unnecessarily stop all the bundles of the OSGi application?
Thanks in advance.
Some code:
Countdown
public void countDown()
{
int i = delay;
while (i>0){
try {
i--;
Thread.sleep(1000); // 1000ms = 1 s
}
catch (InterruptedException e) {
//countdown failure? --> nah
}
}
}
Sender
Thread t = new Thread(new Countdown(5));
t.start();
while (t.isAlive());
System.out.println("Sending the message");