Solved

Problem: A program invoking remote objects through RMI refuses to exit

Posted on 2003-11-19
49
918 Views
Last Modified: 2013-12-29
I've got a program calling remote beans on a server (running on JBOSS 246) , and the program works fine. the only problem is that my process (the client) never exits. i've tried, as you can see below, to close the context and the objects on my end - but that doesn't help. also tried to unexport the registry, and that didn't work.

Any ideas?



Here's the code (even though it references other code parts on our end,which are compiled code to me)

String provider = "anfield:1099";
            TopazConfiguration conf = TopazConfiguration.getInstance();
            String url            = conf.get ("global.configuration.topaz.jndi.provider.url",            "localhost:1099");
            String urlPkgs      = conf.get ("global.configuration.topaz.jndi.factory.url.pkgs",      "org.jboss.naming");
            String facInit      = conf.get ("global.configuration.topaz.jndi.factory.initial",      "org.jnp.interfaces.NamingContextFactory");
            Hashtable hash = new Hashtable();
            hash.put ("java.naming.provider.url",            (provider != null) ? provider : url);
            hash.put ("java.naming.factory.initial",      facInit);
            hash.put ("java.naming.factory.url.pkgs",      urlPkgs);

            InitialContext context = new InitialContext (hash);
            AlertHome objHome = (AlertHome) context.lookup ("com.mercury.topaz.tmc.bizprocess.Alert");
            AlertTBP moshe = objHome.create();

            //AlertTBP moshe = AlertFactory.create();
            try {
                moshe.insertRecipientObject(rcp);
            } catch (Exception e) {
                e.printStackTrace();  //To change body of catch statement use Options | File Templates.
            }

            moshe = null;
            objHome = null;
            context.close();
            //context.unbind("com.mercury.topaz.tmc.bizprocess.Alert");



        } catch (NamingException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        } catch (CreateException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        } catch (RemoteException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        }


         System.out.println("i got here");
0
Comment
Question by:tzvika179
  • 12
  • 11
  • 11
  • +3
49 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9777505
Where does it get to?

does it do the:

System.out.println("i got here");

line?

Have you tried putting more debug in...to see where it freezes?

Are you sure it's not getting caught in some other bit of code other than here?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777506
I think you might need to post some more code...
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9777516
Does the following line return?

>> moshe.insertRecipientObject(rcp);

(ie. if you add an "i got here" after this line, is it displayed?)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9777520
;-)  Hi Tim.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777523
:-)  Morning :-)
0
 

Author Comment

by:tzvika179
ID: 9777555
yea, as i said, the code i didnt post is compiled code to me, i just have the jars, so i can't see the content

and yes it does get to the i get here :-)   in fact the program doesnt freeze at all ! it just doesn't exit when main() is done - which to me is weird .

can anyone say anything about maybe unbind? i'm not sure what name needs to be given to it.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9777572
 Why don't you just do a System.exit() if it is the client?
0
 

Author Comment

by:tzvika179
ID: 9777578
System.exit will work, but i dont want to
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777580
That can't be all your code?

That won't compile...

Can you post all your code?

Tim
0
 
LVL 35

Expert Comment

by:girionis
ID: 9777589
> System.exit will work, but i dont want to

  Why not?

  You probably have some dangling objects doing some background processing that's why it doesn't exit.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9777600
Maybe one of the threads is blocked. Do a thread dump to try and detect this (Ctrl-Break)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777628
Or post your code
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777633
Ooooh...  CEHJ is here early :-)
0
 

Author Comment

by:tzvika179
ID: 9777665
How do i do the thread dump thingi , i am using intellij or just tell me in command
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9777696
Don't know that IDE. You may be able to inspect the threads through its gui.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9777705
>>Ooooh...  CEHJ is here early :-)

I'm late aren't I? ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777710
do you start any threads?  Create any object that block? etc...

without seeing the code, I'm only guessing what it could be...
0
 
LVL 35

Expert Comment

by:girionis
ID: 9777717
 I still can't understand why System.exit() is not a good solution since we are talking about the client.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9777720
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9777730
>>I still can't understand why System.exit() is not a good solution since we are talking about the client.

Papering over cracks?
0
 
LVL 35

Expert Comment

by:girionis
ID: 9777734
 Make it work first and optimize later :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777745
> Papering over cracks?

Not really...more like slamming the door on your way out ;-)
0
 

Author Comment

by:tzvika179
ID: 9777759
i dont start any threads.

here's the thread dump:

Full thread dump Java HotSpot(TM) Client VM (1.4.1_03-b02 mixed mode):

"DestroyJavaVM" prio=5 tid=0x00236008 nid=0x1f10 waiting on condition [0..6fadc]


"Thread-17" prio=5 tid=0x0AEFEFB8 nid=0x1f34 waiting on condition [bb9f000..bb9f
d8c]
        at java.lang.Thread.sleep(Native Method)
        at com.mercury.topaz.util.ObjectPool$ShrinkerThread._sleepUntilNextTime(
ObjectPool.java:202)
        at com.mercury.topaz.util.ObjectPool$ShrinkerThread.run(ObjectPool.java:
115)

"Thread-15" prio=5 tid=0x0AF19BE8 nid=0x1f30 waiting on condition [bb5f000..bb5f
d8c]
        at java.lang.Thread.sleep(Native Method)
        at com.mercury.topaz.util.ObjectPool$ShrinkerThread._sleepUntilNextTime(
ObjectPool.java:202)
        at com.mercury.topaz.util.ObjectPool$ShrinkerThread.run(ObjectPool.java:
115)

"Thread-13" prio=5 tid=0x0AEFB9D8 nid=0x1f2c in Object.wait() [bb1f000..bb1fd8c]

        at java.lang.Object.wait(Native Method)
        - waiting on <02FC94D8> (a com.mercury.util.threads.ThreadPool$MonitorRu
nnable)
        at com.mercury.util.threads.ThreadPool$MonitorRunnable.run(ThreadPool.ja
va:384)
        - locked <02FC94D8> (a com.mercury.util.threads.ThreadPool$MonitorRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-12" prio=5 tid=0x0AF072E8 nid=0x1f28 in Object.wait() [badf000..badfd8c]

        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9538> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9538> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-11" prio=5 tid=0x0AF06858 nid=0x1f24 in Object.wait() [ba9f000..ba9fd8c]

        at java.lang.Object.wait(Native Method)
        - waiting on <02FC95A0> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC95A0> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-10" prio=5 tid=0x0AF05DE0 nid=0x1f20 in Object.wait() [ba5f000..ba5fd8c]

        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9608> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9608> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-9" prio=5 tid=0x0AF053F0 nid=0x1f18 in Object.wait() [ba1f000..ba1fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9670> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9670> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-8" prio=5 tid=0x0AF04A88 nid=0x1ed0 in Object.wait() [b9df000..b9dfd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC96D8> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC96D8> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-7" prio=5 tid=0x0AF04120 nid=0x1f0c in Object.wait() [b99f000..b99fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9740> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9740> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-6" prio=5 tid=0x0AF0B9D0 nid=0x1970 in Object.wait() [b95f000..b95fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC97A8> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC97A8> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-5" prio=5 tid=0x0AEF8DE8 nid=0x1f08 in Object.wait() [b91f000..b91fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9810> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9810> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-4" prio=5 tid=0x0AF02F90 nid=0x170 in Object.wait() [b8df000..b8dfd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC9878> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC9878> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"Thread-3" prio=5 tid=0x0AF07B30 nid=0xa44 in Object.wait() [b89f000..b89fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FC98E0> (a com.mercury.util.threads.ThreadPool$ControlRu
nnable)
        at java.lang.Object.wait(Unknown Source)
        at com.mercury.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.ja
va:430)
        - locked <02FC98E0> (a com.mercury.util.threads.ThreadPool$ControlRunnab
le)
        at java.lang.Thread.run(Unknown Source)

"RMI RenewClean-[192.168.88.101:4444]" daemon prio=5 tid=0x0AEF22C8 nid=0x19d0 i
n Object.wait() [b81f000..b81fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02FAB2A0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <02FAB2A0> (a java.lang.ref.ReferenceQueue$Lock)
        at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(Unknow
n Source)
        at java.lang.Thread.run(Unknown Source)

"GC Daemon" daemon prio=2 tid=0x0AD1B520 nid=0x1f1c in Object.wait() [b79f000..b
79fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02F91100> (a sun.misc.GC$LatencyLock)
        at sun.misc.GC$Daemon.run(Unknown Source)
        - locked <02F91100> (a sun.misc.GC$LatencyLock)

"RMI RenewClean-[192.168.88.101:4767]" daemon prio=5 tid=0x0AD1B260 nid=0x1290 i
n Object.wait() [b75f000..b75fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02F90DD8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <02F90DD8> (a java.lang.ref.ReferenceQueue$Lock)
        at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(Unknow
n Source)
        at java.lang.Thread.run(Unknown Source)

"Thread-1" daemon prio=5 tid=0x0AD5A960 nid=0x1d9c waiting on condition [b29f000
..b29fd8c]
        at java.lang.Thread.sleep(Native Method)
        at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)

"Signal Dispatcher" daemon prio=10 tid=0x008C7C78 nid=0x1b04 waiting on conditio
n [0..0]

"Finalizer" daemon prio=9 tid=0x0090B9B8 nid=0x1cf0 in Object.wait() [ab5f000..a
b5fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02F02FE0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <02F02FE0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x0090AD48 nid=0x14a8 in Object.wait() [a
b1f000..ab1fd8c]
        at java.lang.Object.wait(Native Method)
        - waiting on <02F03048> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Unknown Source)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <02F03048> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=5 tid=0x00909B10 nid=0xb3c runnable

"VM Periodic Task Thread" prio=10 tid=0x008C66D0 nid=0x1efc waiting on condition

"Suspend Checker Thread" prio=10 tid=0x008C7290 nid=0x5ec runnable
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9777789
Can you post your code?  Or the smallest subset of your code that compiles, and locks up?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 86

Expert Comment

by:CEHJ
ID: 9777802
You're not running the server in the same JVM are you by any chance?
0
 
LVL 92

Expert Comment

by:objects
ID: 9778075
>  it just doesn't exit when main() is done - which to me is weird .

Just cause main() has finished doesn't mean your app will exit.
There are other threads running and unless you have means to stop these threads (which u may not) then System.exit() is your only alternative.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9778135
You're up late objects :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9778148
yes, a bit busy down here at the moment.
0
 
LVL 92

Expert Comment

by:objects
ID: 9778162
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9778249
Are you using something like Mercury as well?
0
 
LVL 92

Expert Comment

by:objects
ID: 9778306
> Are you using something like Mercury as well?

Thats pretty obvious isn't it ;)
And yes it is one of the threads I mentioned above.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9778454
>>Thats pretty obvious isn't it ;)

Not necessarily. If it's so obvious, can you explain the correlation between this matter and your previous link posting talking about a supposed bug in RMI?

If you're using a diagnostic tool and it's operating through non-code hooks, then you probably will have to System.exit. Otherwise close the diagnostics down explicitly.
0
 
LVL 92

Expert Comment

by:objects
ID: 9778460
I counted about 13 threads that are running that you'll need to terminate before your app will exit, or use System.exit(). All from a thread pool by the looks of it.

0
 

Author Comment

by:tzvika179
ID: 9778464
I'm not sure i got your conclusion - should i be looking into some threads that i have opened without being aware of it, or should i be looking at unbind and unexport?
0
 
LVL 92

Expert Comment

by:objects
ID: 9778497
tzvika179> should i be looking into some threads that i have opened without being aware of it

I'd start with those threads first.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9778499
Can you post exactly how you start your program, including all command line parameters?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9778507
And maybe the source code?
0
 

Author Comment

by:tzvika179
ID: 9778511
and another thing: in my case it's not latency of several minutes - i waited hours
0
 
LVL 92

Expert Comment

by:objects
ID: 9778533
Check mercury's doco, it may tell you how to shut things down.
0
 
LVL 92

Expert Comment

by:objects
ID: 9778544
> in my case it's not latency of several minutes - i waited hours

It may never shut down. Until all those threads have ended it will not exit, and if there is no timeout on the wait()'s it will be foirever.
0
 
LVL 92

Expert Comment

by:objects
ID: 9778565
Especially check the documentation on its thread pool.
0
 

Author Comment

by:tzvika179
ID: 9778590
i am mercury :-)  
i am now going to decompile the jars (the guy who wrote them is on vacation, of course...) to try to see what is going on on the server side. maybe get some more additional info


command line is:
java.exe -classpath C:\javaprojects\AlertsTester\classes;.\lib\topazdbutilities.jar;.\lib\topazmetadatautilities.jar;.\lib\topazqautils.jar;.\lib\topazutil.jar;.\lib\activation.jar;.\lib\aesrequests.jar;.\lib\commons-collections.jar;.\lib\commons-pool.jar;.\lib\concurrent-utils.jar;.\lib\connection-pool.jar;.\lib\crimson.jar;.\lib\dataselector.jar;.\lib\datatypesifs.jar;.\lib\idgen.jar;.\lib\javacore.jar;.\lib\jboss.jar;.\lib\jce1_2_1.jar;.\lib\jmdrv.jar;.\lib\jrequestor.jar;.\lib\legacyutils.jar;.\lib\local_policy.jar;.\lib\mail.jar;.\lib\object-pool.jar;.\lib\security.jar;.\lib\seropto.jar;.\lib\soap.jar;.\lib\sprinta2000.jar;.\lib\sunjce_provider.jar;.\lib\topazjmdrv.jar;.\lib\us_export_policy.jar;.\lib\xalan.jar;.\lib\xdr.jar;.\lib\xdr_utils.jar;.\lib\xerces.jar;.\lib\xmlwrapper.jar;.\lib\alert_updates.jar;.\lib\connection-pool-mng-jmx.jar;.\lib\ejb.jar;.\lib\ejb2.0.jar;.\lib\genericdataviewcreator.jar;.\lib\jboss-client.jar;.\lib\jboss-jaas.jar;.\lib\jbosssx-client.jar;.\lib\jms.jar;.\lib\jnp-client.jar;.\lib\jta-spec1_0_1.jar;.\lib\junit.jar;.\lib\log4j.jar;.\lib\logger.jar;.\lib\mtime-client.jar;.\lib\mtime.jar;.\lib\MTJUnit-1.jar;.\lib\open_api.jar;.\lib\sboxdata.jar;.\lib\servlet.jar;.\lib\tmc_ex_data.jar;.\lib\transheaders.jar;.\lib\tmc-client.jar;.\lib\tmc-shared.jar;.\lib\tmcalert-client.jar;.\lib\tmcalert-jboss-server.jar;.\lib\tmcalert-shared.jar com.mercury.infra.qa.alertstester.AlertsTester
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 9778620
> i am now going to decompile the jars

Don't you have any documentation, not even any javadoc?

What you want to be looking for is details on your thread pool implementation, and how to empty the pool.
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 150 total points
ID: 9778632
what is:

com.mercury.topaz.util.ObjectPool$ShrinkerThread

and

com.mercury.util.threads.ThreadPool$MonitorRunnable.run

I think these will be the troublesome threads that aren't dying...

espescially the second one...

I guess this is the utilities jar that you don't have the source for?

Tim
0
 

Author Comment

by:tzvika179
ID: 9778695
yup once jad decompiles com.mercury.topaz.util.ObjectPool and com.mercury.util.threads.ThreadPool hopefully we'll know more
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 9778698
There should be something like a close method on the pool implementation that you should place and call in a finally block in your code
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9778783
(but of course that may appear at a higher level)
0
 

Author Comment

by:tzvika179
ID: 9786781
found the culprit. thx to everyone
0
 
LVL 92

Expert Comment

by:objects
ID: 9791860
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now