简体   繁体   中英

Java Standalone Program to JSP communication

The following programs exist: 1. I have a java application which accepts bio potential data every second or two and stores it in the database. This is a socket server which accepts this data from multiple clients and spawns a new thread for processing it to store in the db. 2. I have a jsp page on tomcat server which reads historic client data from database (stored by application 1) and displays it on the page.

The socket server program in 1.) above is not running inside of tomcat server.

The new requirement now is : Display all of the human data coming in live on the jsp page.

Now the problem: I will now need to pass the live data from socket server (which is stand alone) to the jsp which is running on a tomcat server.

Possible solutions:

APPROACH 1: Run the socket server in the tomcat instead of stand alone and store the frequently incoming data in a java object so the jsp can access this object every second and display it on a graph.

PROBLEM : The stand alone java application does not need to be included in a tomcat server except for the fact that the jsp needs access to the live data. Also, I have read that this is not the best way.

APPROACH 2: Expose the stand alone java application as a web service and communicate with the jsp using REST architecture.

PROBLEM : The complication of using this method is that it will not have the flexibility offered by websockets or server sent events (SSE) of auto updating the latest data. The jsp will have to keep polling for new data every one second which is also not a very good option.

I need suggestions on which is a better method for accomplishing my task. Or is there a third better way which I have completely missed.

I have a java application which accepts bio potential data every second or two and stores it in the database

You already have the answer: just display required data from this database in your jsp page. This will be easiest solution.

I undestand that you're trying to display realtime data, but JSP itself is not designed for realtime output, you will have the delay anyway and because you already have required data in database - no need to transport it to Tomcat server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM