Skip to main content

Stopping JXTA problem!

15 replies [Last post]
kultcrowd
Offline
Joined: 2007-09-05
Points: 0

Hello,

I have developed an application that uses JXTA but I need to stop it and start it when desired. This is the code I use for stopping the application:

netPGDiscoveryService.removeDiscoveryListener(this);
manager.registerShutdownHook();
netPeerGroup.stopApp();
netPeerGroup.unref();
netPeerGroup = null;
manager.stopNetwork();

This code stops jxta, but I doesn't stop all the threads created by JXTA. I have several threads still alive once JXTA is stopped. For example:
ThreadedMessenger for tcp://192.18.37.39
ThreadedMessenger for http://192.18.37.39
Endpoint Destinations GC
EndpointRouter Timer for urn:jxta:jxta-NetGroup
BlockingMessenger self destruct timer

Due to this threads, if I start again JXTA from my application, I am not able to connect to rendezvous peers and JXTA doesn't work properly.
Is there any way of stopping these JXTA threads without stopping the JVM?

Thanks in advance

Kult

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bondolo
Offline
Joined: 2003-06-11
Points: 0

It appears that something is keeping the HttpClientMessenger open. I suspect that once the HttpMessenger is closed then most of the rest of the threads should shut down. If this thread dump was taken right after the stopNetwork() call then a few seconds might be required for everything to shut down in an orderly fashion (if you are running http in server mode Jetty can take up to 2 minutes to shut down completely).

If after 30 seconds these threads are still around you'll need to figure out what is holding the reference preventing shutdown from completing. We have previously used jdump and jhat to trace the object references that prevent all of the instances from finalizing.

To get the VM to cleanup some of the static Timer instances you may also need to enable class GC.

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

Thanks for your answer bondolo. Well, I have been debuging the code using eclipse and I am able to see that all the HttpClientMessengers are closed once the time passes. But the following threads are still around:
- Endpoint Router Timer for urn:jxta:jxta-NetGroup
- Endpoint Destinations GC
- BlockingMessenger self destruct timer

And there is one more thread that is not a timer:
- Listener Adaptor -> This thread is blocked on line 412 of the net.jxta.endpoint.ListenerAdaptor class in the run() function. This is the code where this threads blocks:

public void run() {
try {
while (!shutdown) {
try {
Collection changed = selector.select(); ***HERE***
for (SimpleSelectable simpleSelectable : changed) {
ListenerContainer listeners;
......
I am able to see that shutdown variable is false. Why? Is there a bug in here? Should be this thread interrupted once the endpoint service is stopped?
These threads stay alive even after 10 minutes... Any suggestions?
If I create a new instance of my application and start JXTA again, I can see that the Listener adaptor thread is still running and used by the new JXTA instace (the listener adaptor thread that was blocked, unblocks once I start JXTA again and the shutdown variable is still false).

Why I get the RDVFAILED and RDVCONNECT events all the time when JXTA is restarted. Do you think this is related to the Listener Adaptor thread problem?

Thanks in advance!

Kult

marco1a
Offline
Joined: 2005-11-14
Points: 0

I have been downloaded jdump.zip but this file does not have content... what another dumper i can use?

bondolo
Offline
Joined: 2003-06-11
Points: 0

Sorry, i was mistaken when I said jdump. I meant jmap (which is included with the jdk). jmap has a dump option:

jmap -dump:format=b,file=jxtaheap.bin

bgrieder
Offline
Joined: 2006-12-02
Points: 0

Hi,

Did anyone find a solution to this problem?

Bruno

ivarulz
Offline
Joined: 2007-08-17
Points: 0

Indeed, anybody found solution?

It would be nice if people raising the issue could share their solution with others.

My proble:
1) start platform, connect to RDV OK
2) stop platform OK
3) re-start (without shutting down the JVM) - FAILS on RDV connection

Adrian

Message was edited by: ivarulz

marco1a
Offline
Joined: 2005-11-14
Points: 0

Well.. So after I stop JXTA in my app I made a dump of the ThreadGroup. The result

java.lang.ThreadGroup[name=Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22,maxpri=10]
Thread[CM GC Thread interval : 60000,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[Discovery Srdi Thread,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[SrdiIndex GC :pipeResolverSrdi every 60000ms,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[Pipe Resolver Srdi Thread,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[Relay Client Worker Thread for relay://uuid-E670E75234B8405D94908629ABC111ZZ22EC5A6728045C2B10C92E08782C1DB03,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[BlockingMessenger self destruct timer,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
Thread[HttpClientMessenger poller for http://200.201.60.183:80/,6,Group urn:jxta:uuid-E670E75234B8405D94908629ABC111ZZ22]
java.lang.ThreadGroup[name=TLSTransport jxtatls://uuid-E670E75234B8405D94908629ABC111ZZ22EC5A6728045C2B10C92E08782C1DB03,maxpri=10]
java.lang.ThreadGroup[name=Group urn:jxta:uuid-1E684FB2F9F74FD593D88F27B5D05ABC111ZZ2234B8405D94908629ABC111ZZ22,maxpri=10]
Thread[CM GC Thread interval : 60000,5,Group urn:jxta:uuid-1E684FB2F9F74FD593D88F27B5D05CD5E670E75234B8405D94908629ABC111ZZ22]
Thread[SrdiIndex GC :pipeResolverSrdi every 60000ms,5,Group urn:jxta:uuid-1E684FB2F9F74FD593D88F27B5D05CD5E670E75234B8405D94908629ABC111ZZ22]
Thread[Pipe Resolver Srdi Thread,5,Group urn:jxta:uuid-1E684FB2F9F74FD593D88F27B5D05CD5E670E75234B8405D94908629ABC111ZZ22]

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

So did you have any success stopping these threads?

Hamada, Bondolo, could you give us some help on this?

Thanks,

Kult

marco1a
Offline
Joined: 2005-11-14
Points: 0

Compadre I can resolve the restart of the platform.. We most detect a way of to kill the Threads.. I think that I have this problem Know.. I will invest and Call Back

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

I attach a sample application where I start and stop JXTA several times if you want to test the problem I have posted. Debug the application so you will be able to see the "wild" threads.

Thanks

marco1a
Offline
Joined: 2005-11-14
Points: 0

netPeerGroup.globalRegistry.unRegisterInstance(netPeerGroup.getPeerGroupID(), netPeerGroup);
netPeerGroup.stopApp();
netPeerGroup.unref();
netPeerGroup = null;
System.gc();
System.runFinalization();
System.gc();

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

Thanks for your solution, but it still doesn't solve my problem :(
I still have the threads alive and I don't get a successfull connection with the Rendezvous Peers.
I should not be a problem, but the application using JXTA runs inside an OSGi bundle. Do you think this is the reason why JXTA doesn't stopps correctly?
Someone has another solution?

Thanks in advance

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

I made a small application that starts and stops the JXTA framework (without using OSGi) and I found the same problem. The threads mentioned above are still alive when I stop the JXTA network, and when I restart it, I get also the same errors. So OSGi shouldn't be a problem. Might this be a bug in JXTA? Should I report it?

marco1a
Offline
Joined: 2005-11-14
Points: 0

I need to know the same... I got this when i try to restart the netPeerGroup

net.jxta.exception.PeerGroupException: Only a single instance of the World Peer Group may be instantiated at a single time.
at net.jxta.peergroup.WorldPeerGroupFactory.newWorldPeerGroup(WorldPeerGroupFactory.java:282)
at net.jxta.peergroup.WorldPeerGroupFactory.(WorldPeerGroupFactory.java:178)
at net.jxta.peergroup.NetPeerGroupFactory.(NetPeerGroupFactory.java:304)

kultcrowd
Offline
Joined: 2007-09-05
Points: 0

Well, I think we have different problems because I can get a new instance of the World Peer Group and the NetPeerGroup. How is your code for stopping JXTA?

My problem starts when I tries to connect to the rendezvous peers, because the peer connects and disconnects from the RDV continuously. Here you can see the logs I get:
2008-06-17 09:11:06,421 INFO com.eu.hydra.network.backbone.BackboneManagerApplication - RendezvousEvent: Event = RDVCONNECT from peer = urn:jxta:uuid-59616261646162614A7874615032503354C1DDB08EE5422AA522990F4AC79F9303
2008-06-17 09:11:20,718 INFO com.eu.hydra.network.backbone.BackboneManagerApplication - RendezvousEvent: Event = RDVFAILED from peer = urn:jxta:uuid-59616261646162614A7874615032503354C1DDB08EE5422AA522990F4AC79F9303
17-jun-2008 9:11:21 net.jxta.impl.rendezvous.edge.EdgePeerRdvService addRdv
INFO: New RDV lease from urn:jxta:uuid-59616261646162614A7874615032503354C1DDB08EE5422AA522990F4AC79F9303 C : -1213686681313 / -1213686681312
2008-06-17 09:11:32,718 INFO com.eu.hydra.network.backbone.BackboneManagerApplication - RendezvousEvent: Event = RDVCONNECT from peer = urn:jxta:uuid-59616261646162614A7874615032503354C1DDB08EE5422AA522990F4AC79F9303
2008-06-17 09:11:35,718 INFO com.eu.hydra.network.backbone.BackboneManagerApplication - RendezvousEvent: Event = RDVFAILED from peer = urn:jxta:uuid-59616261646162614A7874615032503354C1DDB08EE5422AA522990F4AC79F9303

Anybody knows how to solve this problem?

Thanks,

Kult