Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Run a background process in startup class for UDP listener

843830Apr 7 2006 — edited Dec 19 2006
Hello,

I want to implement a solution where EJB send asynchronous messages to other EJBs using UDP (DatagramPacket class).

I want to start the listener using my startup class but this listener, to work correctly, is inside an infinite loop (each time a message is received, then continue to listen for others). So the application server (I'm using weblogic) isn't starting correctly (get stucked in "starting mode").

My idea is to start this listener in background but I have no idea on how to do it.

Code sample :


Startup class :
public class MonitorStartup implements T3StartupDef
{

public MonitorStartup () {}

public void setServices(T3ServicesDef t3servicesdef) {
}

public String startup(String s, Hashtable props) throws Exception {

System.out.println("******* Starting UDP listener ***************");
MonitorServer monitorServer = new MonitorServer();
monitorServer.receiveMessageInformation();

return null;
}

} // end of class


MonitorServer :

public void receiveMessageInformation () {

try {

DatagramSocket socket = new DatagramSocket(BROADCAST_PORT);

DatagramPacket packet = new DatagramPacket(new byte[PACKET_SIZE],PACKET_SIZE);

while ( true ) {
socket.receive( packet );
System.out.println( "RECEIVED A PACKET");

} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


Any help is appreciated ....

Christophe
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 16 2007
Added on Apr 7 2006
3 comments
229 views