Cronjob with JavaServlets on TomCat Server [duplicate] - java

This question already has answers here:
How to run a background task in a servlet based web application?
(5 answers)
Closed 6 years ago.
I have a webpage written with jsp and Java Servlets on a TomCat-Server.
I am very new to the whole JavaServlet thing. In the past I developed often in php. There it is very simple to create a Cronjob.
I just used CRONTAB and called a .php-file which did the job for me.
But how do I do this with JavaServlets? I read that some say the quartz-library would be good. But I didn't really get how to use this. I don't know where to start.
I know that this question isn't very detailed and I can't provide any code, because there is no. I just wonder if there is any possibility to just call a JavaServlet like I can in php with crontab.
My goal is to call a method every five minutes on my server. Most times this method will finish very quickly, but sometimes it will execute another .jar and last many minutes.
Any advice would be very helpful for me. Thanks!

I recommend that you do take a look at Quartz when you have time.
We have found it to be quite useful for handling cron-like task running.

Related

I am having selenium script in Java, i need to run it every one hour automatically with out my intervention.How to do it? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to run my Java selenium script every one hour.I want to do it without Human intervention.How to do it?
Can i do it by keeping my piece of code in cloud or any online IDE which runs it every one hour?
Please help in this case.
I have seen some people suggesting Windows Task scheduler,but the file should run even my computer is shutdown.
Windows scheduled task. https://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx
Cron job https://www.digitalocean.com/community/tutorials/how-to-schedule-routine-tasks-with-cron-and-anacron-on-a-vps
I would use something like Jenkins, or AWS to run your job (on a schedule).
You can create tests packed as an executable the easiest way may be to run a CRON job or a Windows scheduled task.
Or
If you have Hudson (or another continuous integration system like jenkin ) can be use for it and is almost certainly better long term strategies.
However this question is quite broad, I can give you a general approach with a suggestion. That you need is to persist the application where is the script, method or whatsoever included and call it every 60 minutes.
In general, I'd suggest you create a web service and deploy it on Azure's Tomcat servlet container. You need a web page available online, where you can periodically call with AJAX the Selenium method mapped to the exact URL.
The disadvantage may be the complexity of the client-side and server-side concept if you have the lack of experience. However, you can monitor the activity and the results for your own and scale the web service.
You can use any only CI environments for this task. For example free and easy to configure is travis-ci it has integration with github and lot of documentation for how to run it.

How can i embedd a java applet in blogger [duplicate]

This question already has answers here:
Embedding Java Applet into .html file
(2 answers)
Closed 6 years ago.
How can i embed a java applet in blogger. I am writing a blog on blog spot.com and I want to attach a java applet in that. Is it possible to do so? if yes, then how?
I tried to write this code in blog's html tab
<applet code="calculator.class" height="500" width="500"></applet>
but it doesn't work...
You don't.
Probably nobody told you so far, but applets are "dead technology". The only reason to do anything with Applets in 2016 is because you are working in some company that still uses them for some of their internal stuff. Then, and only then you should be spending your time on learning/programming applets. But in any other case, you would be wasting your time.
You see, browser like chrome have stopped supporting Java/applets quite some months ago.
Nobody does reasonable front work using applets any more. In other words: look into JavaScript or any of the huge frameworks around that. And figure how to use something like that instead of applets.

Java. How to make a bot [duplicate]

This question already has answers here:
How can a program control another program?
(11 answers)
Closed 8 years ago.
I wonder is possible to make a bot writen in JAVA, which will open some program(program is under windows), click on the button in this program and type some data, check status of this program(login or logout, this is client for online game).
Which JAVA tools I need ? I think that java robot lib is not enough for this.
Thanks in advance.
You cannot do this using JAVA.
JAVA is a language which is loosely coupled with operating systems, so it can only receive mouse/key messages from underlying OS. Among all the tasks you mentioned , it can only start the program by using Runtime.execute.
If you want to implement a software like this ,you should use Visual Studio and use Microsoft technologies.

Delegating workload from Java Servlet [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm attempting to build a Java Servlet task that has a runtime of about ~15-20 minutes that takes arguments from a HTML form. I have a couple of questions regarding this:
Will the task continue to run even after the user closes the browser? I Googled this and it seems the process will continue to execute even after browser close. I just want to confirm this.
While searching for the answer for the above question, I came across a post (or a couple of them) that stated that for such 'intensive' (I would consider mine intensive as it takes around 15-20 minutes to complete) tasks, it's better to have a separate program run the task than containing it in the servlet program. So, do I just execute another Java program from the servlet class?
And now for my final question, will multiple user requests be processed independent of each other? As in, will the servlet have a separate thread or instance for each request? If so, will my execution of another Java program from the servlet class lead to any problems?
There are a few items to discuss, each with their own (part of a) solution:
Do you really want the task to continue if the browser closes? Spawn a new thread for the task (Trying to write to the browser outputstream when browser is already closed will make the thread die in an exception) See Executor
Do you want concurrent requests to be handled in parallel? How many in parallel? See ThreadPoolExecutor
Do you want feedback to the browser (user) during the long running task? See Async servlets
The servlet container will make sure that parallel requests are handled concurrently, each in their own thread. But they will share the instance of the Servlet class. Therefore, you have to make your code thread safe.
About running a 'separate java program' or keeping the task in the servlet: it is best practice to separate different tasks in a program in different sections. Creating a new class for your long running task is better than keeping it in the servlet class. See Separation of concerns.

How to test if a file is open in Java? [duplicate]

This question already has answers here:
Check if file is already open
(8 answers)
Closed 4 years ago.
Is it somehow possible to test if a java.io.File is currently open in another process by any process ? I am using Java 7 and target platforms are Linux/Windows/Mac.
There is no easy way in Java to go about this that will work reliably across different platforms. Depending on what you're trying to do, you might be able to patch together a series of try/catch statements which ostensibly work for most cases on most file systems, but you can never have full certainty that the next situation it encounters won't throw it off.
If you do end up going this route you want to ensure that when there is any doubt, it fails fast and doesn't get into a situation where it thinks a file is not open when it really is. My advice would be to see if there is any way you can possibly work around having to do this check.

Categories

Resources