For a VAADIN Java Application running on Tomcat7 with Neo4j Database System, i need to create a routine that checks all users everyday at 12AM, and sends email to all of the users who have been returned by my request (the request is ready, and works well).
The problem is here:
I don't know how to start one of my class each day at 12 AM in the application, i already tried Quartz and Java.ejb.Schedule but none of them have worked, Quartz creates me a memory error and only starts the class once, and ajb is simply not working (no loop at all).
Is there an easier way to achieve this? i just need to start my class each day, even if no users are on the application.
Related
Production Environment: Tomcat 9 on CentOS 7 x64, mysql/mariadb 5.5x
Testing Environment: Tomcat 9 in Eclipse on Windows 7 x64, mysql 5.5x
I'm a Tomcat newbie looking for the best method to have server-wide variables readable/writable from all Webapps for things like MaintenanceMode(on/off) and MaintenanceMessage, etc.
These are the variable properties I'm looking for:
Readable/writable from all instances of all java servlets on all webapps.
Value persists after OS, Tomcat, or Webapp restart.
I must be able to change the value of it from one webapp and then all other webapps recognize the change quickly, ideally without restarting.
Ideally I wouldn't want to read the variable from disk on each server request. In case server is getting DDOSed or something.
Ideally the solution is OS independent.
If it's a disk file solution please recommend a place for me to store the file.
I'm new to Tomcat so some detail in any answers would be appreciated or links to detail. I'll probably be using a servlet on it's own 'admin' webapp that's only accessible through SSH-tunneling, etc, to set the variables. Then the public webapps would respond to any changes, like showing a maintenance message while I backup databases. I could also possibly change the variables using linux commands if needed.
If I stored the server variables in a database that could be fine but I wouldn't want to read the DB on every single request most likely, and when I change a variable I'd have to once again notify every webapp/servlet that something was changed and to re-read the DB.
Thanks for any help.
I implemented this recently in the form of "system messages", some of which are for maintenance. But the effect is the same. We had some additional "requirements" which helped us form the solution. These may or may not match up to your expectations/desires:
Multiple-server coordination
Immediate synchronization was not necessary
We used our relational database for the actual data storage. A single table with "system messages" and a few other fields such as when the messages became effective (not_before DATETIME) and when the messages became ineffective (not_after DATETIME).
On startup, the application reads the system messages table to find the currently-valid messages and stores them in application scope, including their validity dates. Whenever we want to show them on the screen, we check each item in memory and evict any that have expired. This is pretty fast.
Every X minutes (e.g. from cron), we make a request to a special servlet (on each server) that re-loads the system messages from the database. We protect that servlet by only allowing requests from certain IPs, so DOS is not an issue.
Not only can we add a system message from any server in the cluster, but we can also add one by writing directly to the database. That may be advantageous if you don't always want to use your application to generate these events.
You can change the value for X to anything as low as 1 (minute) if you are using cron. If you use some other kind of system, you can probably get updated even more often. I would seriously reconsider your requirement of "immediate" recognition because that requires a system that has much worse performance.
If you can guarantee that only your application can generate these changes, and you have a list of all other servers in the cluster somewhere, you could theoretically ping them all with the new message (or notify them that a new message exists and it's time to update their message-list), but that kind of thing is better-done with an orchestration tool such as Kubernetes, and we are getting a little out of scope IMO.
I have a Spring Boot app (jar file) that is running on Windows server and is used to sync data between some tables in a database and other parts of infrastructure (consumer apps via ActiveMQ).
It is crucial to have it running 24/7 without any downtime (or with very little).
I am currently trying to find the best way to do this as our current solution is to run multiple instances of the same app and define one to be active and ping it continuously (via an entry in database where it writes every 15 seconds), while other instances are just running and do nothing (inactive state, cause lock is taken). If an active instance has stopped to update lock entry (freeze or crashed) in database one of the available instances will take its place and start to handle data.
I have a feeling, that it is not so flexible solution, especially when I need to prepare different part of my code to check lock entry and sync all those instances. It adds complexity to the code and I want to avoid it.
Is there any better solution? Plugins, implementation pattern or tools?
PS:
I read about health endpoints that are available in a SpringBootApplication and think that it can help me somehow (ping\check them from some other Watchdog software\tool, maybe?), but don't know how.
In case of a crash you still have a delay of 15 seconds while a request can fail
I would go with a zuul router from netflix (open source)
It will balance the load between instances and will retry your request on another instance if the first call has failed
I'm pretty sure it's already done but use windows services to restart instance in case of hard crash
I have created a java application that is inserting data to a mysql database. Under some conditions, i need to post some of these data via email, using a java application that I will write as well.
My problem is that i am not sure how i should implement this.
From what I understand, I could use a UDF inside MySql to execute a java application, for which there are many against opinions into using it. Let alone that both the database and the mail client application will reside in a VM that i dont have admin access, and dont want to install anything that neither me nor the admin knows.
My other alternative, that I can think of, is to set up the mail client (or some other application), to run every minute just to check for newly inserted data. Is this a better aproach? Isn't it going to use resources for doing almost nothing. At the moment the VM might not be heavily loaded, but i have no idea how many applications there might end up running on the same machine.
Is there any other alternative i should consider using?
You also need to consider the speed of internet, database server load, system resources. If you have enough memory and less load to insert data in databases or database load is not so much then you can approach this by cron setup. For linux call a script for every 5 minutes. The script perform the following-
1. Fetch unread Emails as files
3. Perfrom shell script to read needed data.
3. write data to mysql
4. Delete the email
If you have heavy loaded system then wise you need to do this once or twice in an hour or may vary.
OK so here is the scenario.
I have a local Java application running on a desktop. Users/clients need to check in to this (by going through required steps) either every day, every other day, weekly, biweekly, monthly, etc (admin-defined for each user).
In my web application, an admin would add the user and the schedule they need to check in to. If the user does not check in by their required time, then the admin would be alerted of this person and he can complete other actions from there.
How should I go about doing this and should it be done through MySQL or Java? I thought about scheduling events in MySQL but that could not be admin-defined on the web app. I'm not sure what else to do for this.
MySQL is good for storing state. Maintaining records of when they checked in is good, and you can write a script that sees who hasn't checked in when they needed to and alerts the admins. The Java application then just has to update the MySQL record with the current time everytime they check in.
I would like to run a web application and keep running a Class which inserts Data in a Database 24/7 without having a browser open.
If I open a browser I would just like to see which data is beeing inserted right now.
How would I keep this process running in a web application on a Glassfish server without having a website open?
Thanks in advance,
Daniel
Put the data insertion into a plain old java application and start it via the main method.
With your web application show the current state of the data base. Add timestamps to your DB records. This allows to query for new records.