What is the best way to implement a notification system that keeps running in the background?
This system will generate these notifications when certain conditions are met. The server has to monitor the database constantly for these events and update a notification log when they occur. When a notification is generated, an SMS is sent to designated people.
With a traditional JSP system, the code only runs when a user visits the site. How do you program the server to have the code running 24/7? Also, how do you feed back these events asynchronously to the front end so the front end does not need to keep polling the database?
The question is very vague, but i'd say you need a task scheduler, some application servers like wildfly already have a task scheduler, or you can use something like quartz, and set it to run every as many times as you need.
Related
I'm building an ETL that first gets the date from the cache to use in the query to pull from a database, transform the content, and send it to the microservice API.
I have a problem, when I start all the processor, it works fine, but like 40 hours later, the processors stop working, but they are still on, and the queue starts to fill up.
This is my flow to extract data:
And this is my system to update the date:
I tried restart system and this repeats again.
I want this system to always work
I am currently working on a schedule application in Java (Netbeans) and basically, I want to have notifications pop up whenever something is close to being due. I would like them to pop up even when the application is not running. I don't think I'll need a database because all the times and due dates will be specified by the user. Also if it isn't possible to send notifications, is it possible to just automatically open a JFrame on a scheduled time? Thanks!
In a lot of multclient java programs people use a separate thread which only receives the messages from the server. Is it really necessary? Why can't it be done in the main thread? What should be the problem?
For me a separate thread to receive the messages from the server is not that necessary, it could be done simply be the main.
Am I wrong?
No, if it was done in the main method, then the rest of your application would wait until a message is received. This may be fine if your application only received messages. However, if your application did other things like accepting user input in order to send messages then, the application would not be able to do the other tasks(such as user Input) until a message has been received.
EDIT:
It would also have a hard time with multiple clients
Yes you are. At least if you want something pratical.
If you get updates periodical, you need to wait every x ms/s/mins for the server input to be read, if you receive message from the server directly you need to wait everytime someone sends one, and could not even handle multiple messages at once.
Now add a Graphical Interface and youll run into a wall trying to handle that by 1 thread.
Not that it would make sense anyway.
After 6 years I would like to answer myself of the past.
Some more context: the multi-client chat is a GUI chat that used swing. It was a high school project.
The main method would go in a loop to read messages received from a server. Since every other client action is event-based, the event handling would be done on a separate thread anyway.
So yeah, it worked fabulously at the time!
(I'm sorry for the title, it was the best I could come up with)
I have a PlayFramework (2.3) app where my users can upload large csv files that will be processed.
Once the CSV is imported, I run a task that will pass over each new entry, and check a specific data with a request to an external API (for each entry).
Since this takes a long time, I do the checking asynchronously, but I'm facing a structural issue here :
User A upload a file with 100k lines
I add those 100k lines to my async code and start it
User B upload a file with 200k lines
I would add those new lines to the current async code
I stop the app (updating the code)
When restarting, it should start where it stopped.
I thought about a Queue system, but I would loose the interest when starting the app.
Any idea on how I can do this ?
Thank you for your help.
Since the question is structural, I am only going to focus on the high level implementation details :
I stop the app (updating the code)
When you decide to stop the application, you need a way to gradually stop all running threads. For this, every thread that you start in your application should be registered with some sort of a thread manager. This way, when you decide to stop the application by clicking on a stop button/bringing down the app server, your thread manager knows what threads are running and will give these threads a chance to save their state or finish their work without allowing any new threads to be spawned before finally bringing down the main thread itself.
When restarting, it should start where it stopped
To start from where you stopped, you need to save the state of the completed work somewhere. Assuming that you are using a Queue based system, you will have to serialize your queue before the app stops. This way, you won't lose the contents of the queue when you bring back the app.
I am currently building a java web app in netbeans. I have come to a point where I am stuck now. I have a draft application for a sports website I am building. The draft has the ability to have every user in the league access it, but I need it to be synchronized for all of them.
I want to run a java program or method that will create the draft at the specified date and time, then have centralized variables and a timer that each user can access when they access the web page.
So I want every user to see the same thing when they open the draft, regardless of what point in time they open it. Essentially this draft needs to run regardless of whether or not anyone actually opens it.
I am struggling with how I can do this, I was thinking threads, or a cron job, but I have no idea how to gain access to the program I run from my web app using something such as JSTL or jsp:useBean.
Any help at all would be much appreciated.
Since real-time consitency is important to your application.
One simple approach would be to store the draft information in database.
Set the sort order, start time and end time for all records in the database. Since you know this information before hand, you can do this from an admin script. Just run the admin script manually or at a preset time to update the database.
Now, clients can request the records that should be displayed given current time.
Added advantage with this procedure is that your client (JSP) can retrieve users in bunch with start time and end time and display them.
You don't have to make AJAX type of call every 20 seconds.