• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

JavaFx application high CPU/memory usage when user disconnects from Remote Desktop Services

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I start my JavaFX application via Remote Desktop Services . When I disconnect the user on the server (see image in the attachment) java task continues to run and consumes lot of CPU and memory .

What can I do about it?

Thanks in advanced

Regards, Anton
141040.jpeg
[Thumbnail for 141040.jpeg]
 
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Platform.exit()?  Are all your Threads exiting properly?
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am using Platform.exit(); and System.exit(0); in the stop method of my Fx application


But still when user is disconnected an the screen is gone ,JavaFx Application Thread and QuantumRender keeps running
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the System.exit(0) line.  Otherwise Platform.exit() doesn't work properly.
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I can catch Windows event (when disconnecting client) somehow to execute Platform.exit() from there?
 
Master Rancher
Posts: 4223
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you do what Knute suggests and remove the System.exit() call?

Patform.exit() is going to be doing stuff when you suddenly pull the rug from under it with the System.exit so it doesn't get a chance to clean up properly.

In general you shouldn't need to use System.exit().
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing happens because stop method is not being passed at all.
I am looking the place where I can put Platform.exit() to shut down jvm when client is disconnected.
As I already mentioned the application started on remote client by using RDS.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the image it looks like the user would select Disconnect from a context menu.  Are you controlling that menu?
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:From the image it looks like the user would select Disconnect from a Windows context menu.  Are you controlling that menu?


This is exactly the problem. When I select Disconnect from that context menu on server  the application on the client machine shuts down but jvm om the server keeps running and starts to consume the lot of memory and CPU.
It's look like I have to find how to catch events from that Windows menu in my javafx application.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one way to "capture an event" on a context menu item:
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:This is one way to "capture an event" on a context menu item:



I mean the context menu of Task manager in Windows 10 OS.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the OS is creating the context menu?  And one of the options is to disconnect your client process?  Wow.  I don't know how to protect against that.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I can think of is for you to create your own ContextMenu and include Disconnect as a MenuItem.
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:So the OS is creating the context menu?  And one of the options is to disconnect your client process?  Wow.  I don't know how to protect against that.


Yes, This is standard Task Manager context menu in Windows. It not disconnects the process itself but remote desktop session (rds) where from this process is started.
I believe RDS was a popular cloud solution nowadays.
So when user is disconnected (by Disconnect user from Task Manager) the client session looses the actual GUI but the GUI thread keeps running on the server machine and consuming the lot of resources



 
Saloon Keeper
Posts: 2690
343
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe try using Screen and see if you can detect any change in the screen attributes with:
    Screen.getPrimary().getDpi()
    Screen.getPrimary().getBounds()


or try adding a listener using Screen.getScreens() and see what changes it reports when the remote user disconnects.
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So when user is disconnected (by Disconnect user from Task Manager) the client session looses the actual GUI but the GUI thread keeps running on the server machine and consuming the lot of resources



I don't work with JavaFX but what seems to be happening is that you are just shutting down the connection to the Server machine with the Java app .
That doesn't shut down the app so it will continue to use resources.

If you want to shut it down from a client Windows context. You need to firs trigger the remote app shutdown and then disconnect.
Perhaps use a wrapper script or app on the server  to start and shutdown the Server app from the client/Windows context menu ?

So instead of

I start my JavaFX application via Remote Desktop Services

, start a script or a wrapper java app  that starts the JavaFX app .
If it is a wrapper app , create  a shutdown method that first shuts down the JavaFX app then shut's itself down .

Good luck,
Paul
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:
or try adding a listener using Screen.getScreens() and see what changes it reports when the remote user disconnects.



Thanks Ron, I used method getScreens in my application. I defined the TimerTask whitch periodically prints number of active screens in the log


But unfortunately it keeps determining the screen even after disconnecting the remote user
 
Antonio Banderas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I don't work with JavaFX but what seems to be happening is that you are just shutting down the connection to the Server machine with the Java app .
That doesn't shut down the app so it will continue to use resources.



Yep, This is exactly what happens


start a script or a wrapper java app  that starts the JavaFX app .
If it is a wrapper app , create  a shutdown method that first shuts down the JavaFX app then shut's itself down .

Good luck,
Paul



Now I wrapped my Fx application into Tanuki Java Service Wrapper but without any success

There are  only three method available - start, stop and controlEvent. I supposed I could use controlEvent to capture the disconnect event, but this was not a case


 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't like the System.exit(0) as a way to stop an application with threads running.  I would rather send the thread some signal that it should shut down (see this question on Stack Overflow).

Maybe instead of trying to determine if the user clicks Disconnect you could detect that the JavaFX program is no longer connected and shut down after that?
 
paul nisset
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm not familiar with the Tanuki library. Why are you starting your server app from a new Thread?

controlEvent() seems to be where you are supposed to be controlling your DummyApp/FX app .
I don't see you calling DummyApp.stop() anywhere.

Try this:
Call the stop() method of your FX application from controlEvent() before you call stop() in the Tanuki wrapper app.
Instead of starting your app from the start() method of the Tanuki app ,start it  and stop it from the controlEvent method .
You need a handle for your  app that Tanuki is controlling ,so you can call it's stop() method.

You might have to make DummyApp an instance variable of the DummyAppWrapper class so controlEvent() can see it.

Try something like this where dummyAppInstance is the  instance of your DummyApp.class:

You can use the return value of controlEvent() to determine if your app is has started or stopped.

System.exit()  will crash out of the app without freeing up any resources. Any data connections or file resources etc. will remain open and continue to use up memory.

-Paul
 
Greenhorn
Posts: 11
Android Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to use getScreens. I had the same problem and it helped.
 
Knute Snortum
Sheriff
Posts: 6191
164
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OP has tried getScreens() already in this post.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!