Need help with java web application design for background tasks

I have a local web application that is installed on a desktop PC and needs to regularly synchronize with a remote server through web services.

I have a transaction table that stores transactions that were processed locally and must be sent to a remote server, and this table also contains transactions that were received from a remote server (which were processed remotely) and needed (they were received by calling a web service) ... Transactions are performed in a temporary order to ensure that they are processed in the correct order.

An example of a transaction type is “credits” and “returns” of items from a store, such as a video rental store. For example, something could have been borrowed locally and returned remotely or vice versa, or any sequence of credit / return events.

There is also other information that is retrieved from the remote server to update local records.

When the user performs local tasks, I update the local database in real time and add the transaction to the table for background processing with the remote server.

What is the best approach for handling background tasks. I tried using the Thread created in the HTTPSessionListener and using interrupt () when the session is deleted, but I don't think this is the safest approach. I also tried using the session attribute as a locking mechanism, but that is also not the best approach.

I was also interested in how you know when a thread completed its execution to avoid having another thread dine at the same time. Or before the thread dropped to completion.

I came up with another proposal using the Quartz scheduler, I have not read this approach yet. I'm going to draw a copy of Java Concurrency in practice, but I needed help with ideas for a better approach before I got stuck in it.

BTW I do not use the framework of the web application.

Thank.

+3
2

, . , . (, Tomcat) , ServletContextListener, threadpool Java 1.5, ExecutorService API threadpool . Java 1.5 , Spring TaskExecutor

- Java EE concurrency , Java EE 6.

:

+3

Quartz Scheduling, , . , Concurrency ..

  • , , "Y" "N", - "N"
  • , , , "Y"
  • 'N', ,
+1

Source: https://habr.com/ru/post/1779886/


All Articles