Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet as thread from main java program?  RSS feed

 
Azure Iaorth
Greenhorn
Posts: 10
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have question about servlet, currently I have a Java socket program that needs to be continuously running (monitoring a device), and I want to write a web application to talk to the socket program.
is it possible to launch a servlet thread from my java program when a http request is received? does anyone know how to do that with netbean?

my first plan was to use servlet to make a socket connection to talk to my java socket program upon HTTP request, but then the servlet would have to create and terminate a socket for every page request, that would create delays, i think there is a better way of doing this but i dont know how, can someone give me some ideas? either using servlet or other method.


Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, servlets are executed as part of a web application running in a servlet container such as Tomcat of Glassfish.
 
Ganesh Malaichamy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are planning to display some data related to that monitoring in that web application,Then that standalone socket program needs to write the information in a data source ( file or database).The web application servlet will communicate with the data source to display the data.I hope the web application will be the readonly consumer for the data source.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One approach would be to make all information available via JMX. Then a JMX client can connect to it from remote, retrieve the information, and display it any which way it wants. It wouldn't even have to be read-only - the JMX client can be used to influence the remote app, and t could be embedded in a standalone Java app, a Java web app, or you can use a read-made JMX client such as JConsole or VisualVM (both of which come with the JDK).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!