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

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");
tzvika179Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
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
TimYatesCommented:
I think you might need to post some more code...
0
jimmackCommented:
Does the following line return?

>> moshe.insertRecipientObject(rcp);

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

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

jimmackCommented:
;-)  Hi Tim.
0
TimYatesCommented:
:-)  Morning :-)
0
tzvika179Author Commented:
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
girionisCommented:
 Why don't you just do a System.exit() if it is the client?
0
tzvika179Author Commented:
System.exit will work, but i dont want to
0
TimYatesCommented:
That can't be all your code?

That won't compile...

Can you post all your code?

Tim
0
girionisCommented:
> 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
CEHJCommented:
Maybe one of the threads is blocked. Do a thread dump to try and detect this (Ctrl-Break)
0
TimYatesCommented:
Or post your code
0
TimYatesCommented:
Ooooh...  CEHJ is here early :-)
0
tzvika179Author Commented:
How do i do the thread dump thingi , i am using intellij or just tell me in command
0
CEHJCommented:
Don't know that IDE. You may be able to inspect the threads through its gui.
0
CEHJCommented:
>>Ooooh...  CEHJ is here early :-)

I'm late aren't I? ;-)
0
TimYatesCommented:
do you start any threads?  Create any object that block? etc...

without seeing the code, I'm only guessing what it could be...
0
girionisCommented:
 I still can't understand why System.exit() is not a good solution since we are talking about the client.
0
CEHJCommented:
>>I still can't understand why System.exit() is not a good solution since we are talking about the client.

Papering over cracks?
0
girionisCommented:
 Make it work first and optimize later :)
0
TimYatesCommented:
> Papering over cracks?

Not really...more like slamming the door on your way out ;-)
0
tzvika179Author Commented:
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
TimYatesCommented:
Can you post your code?  Or the smallest subset of your code that compiles, and locks up?
0
CEHJCommented:
You're not running the server in the same JVM are you by any chance?
0
Mick BarryJava DeveloperCommented:
>  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
TimYatesCommented:
You're up late objects :-)
0
Mick BarryJava DeveloperCommented:
yes, a bit busy down here at the moment.
0
Mick BarryJava DeveloperCommented:
0
CEHJCommented:
Are you using something like Mercury as well?
0
Mick BarryJava DeveloperCommented:
> 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
CEHJCommented:
>>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
Mick BarryJava DeveloperCommented:
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
tzvika179Author Commented:
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
Mick BarryJava DeveloperCommented:
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
CEHJCommented:
Can you post exactly how you start your program, including all command line parameters?
0
TimYatesCommented:
And maybe the source code?
0
tzvika179Author Commented:
and another thing: in my case it's not latency of several minutes - i waited hours
0
Mick BarryJava DeveloperCommented:
Check mercury's doco, it may tell you how to shut things down.
0
Mick BarryJava DeveloperCommented:
> 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
Mick BarryJava DeveloperCommented:
Especially check the documentation on its thread pool.
0
tzvika179Author Commented:
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
Mick BarryJava DeveloperCommented:
> 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
TimYatesCommented:
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
tzvika179Author Commented:
yup once jad decompiles com.mercury.topaz.util.ObjectPool and com.mercury.util.threads.ThreadPool hopefully we'll know more
0
CEHJCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
(but of course that may appear at a higher level)
0
tzvika179Author Commented:
found the culprit. thx to everyone
0
Mick BarryJava DeveloperCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.