I have a big xml file that I want to get transferred from c: drive to d: drive at particular time period.
I want to design a Java class to perform a batch job. This would means that the java class will act like a batch job and it will pick the xml file from c: drive and will send it to d: drive at particular time.I want the other time setting and file location specifications to be done in xml file and the rest java class would contain the buisness logic.
Please advise how to achieve this , and also please let me know any of frameworks like Spring or Spring Integration, Spring Batch that might provide any help..!
I am more interested in spring batch!!
I would recommend using your OS scheduler to achieve this. Put your business logic in the Java code any way you want but on windows schedule it with the windows scheduler, on unix use cron.
If you absolutely need Java to be the scheduler as well, look into Quartz.
---- Using Windows Scheduler ----
First, create a batch file to kick off your java code:
myjavarunner.bat:
java -classpath <myclasspath> com.silly.project.ClassWithMainMethod <arguments>
This is not strictly necessary, but when working with java, it is often much easier. Then, create a scheduled task. Click the start button -> Control Panel -> Administrative Tools -> Task Scheduler. Click the Action menu -> Create Task. Fill out all the forms and let er rip.
A simple start would be using a Timer to schedule the periodic job and a TimerTask to implement the business logic.
Related
I am quite a beginner, any advice is much appreciated.
I have a linux application OpenBTS used to simulate and run a GSM network on a software defined radio device e.g USRP.
I want to build an application that interfaces with the OpenBTS command line on Linux. I want to give the user an easier way to configure and to display the current configurations of the application. The user would have an interface in which he could play with the configurations without the need to use the terminal.
I don't know if this is possible ?
Is it possible to interact with a Linux CLI through a GUI ? If yes what is the most efficient programming language, coding technique or approach to do that ?
Thanks a lot
You could generate a config file using your GUI and then use standard in to get the configuration into OpenBts. When launching OpenBts with the configuration file config.txt you could simply run it as follows.
./OpenBts < config.txt
You could also do this from you GUI by launching OpenBts in a process from your GUI application in a similar fashion, however this requires a fork() and exec()
In C++, you can take inputs from user through GUI then run appropriate openBTS commands using system()/popen(). Based on the return values of system()/popen(), can provide status of the operation back to the user.
I have written a Java program which retrieves Google data till present date using Google Analytic API and export it as CSV file. I want this program to run daily so that data in the CSV file will be up to date. How can I achieve this?
You can use the Windows Task Scheduler (see tutorial) to start any program; for Java, you will probably want to create a batch file to run your Java program, then use the Scheduler to run the batch file. The Scheduler provides a "Create Basic Task" wizard for setting up these schedules.
You can also use an executable JAR instead of a batch file, provided that Windows has a file association between JAR files and Java.
You may need to specify the start directory if your task performs IO - see this thread.
Schedule Via Java
Use a ScheduledExecutorService and the method scheduleAtFixedRate with a TimeUnit of Day. Your program will wait a day and then do what it has to do.
Of course your computer has to be on. If that is an issue, it might be better do something like this using Google App Engine.
Have a look at Windows Task Scheduler. Task scheduling can be found under all programs -> accessories -> system tools -> scheduled tasks.
I have a Java - Spring application. I want to set up a feature to listen a file location(Folder) and has to process a file as a file get created in this folder.
My plan is to set up a spring quartz cron job which will run in every five minutes and process the files available.
Please suggest me a better approach.
A choice of solution depends on how quickly an appearance of a waited file must be detected.
If it is not urgently and at least 1 minutes would be OK, then your solution using any kind of cron job would be OK too.
If a file should be detected asap, then you must provide a permanent running program, that detects a file in very short intervals. This can be reached by for this task dedicated daemon. If your program has nothing to do during wait time, then it can contain part for the file detection.
If you have moved on to/are on java8, it provides Watch Service API that allows us to monitor file and folder locations.
Have a look at Watch Service API
I am designing a Java applet based application that has to interact with "KNIME".I want to take a file as input in the applet and send that to "KNIME" file reader.I want to generate a histogram from JFreeChart and and writing the output into a JPEG file through image port writer node.I want the image file output to be displayed in the applet.
May i know how i could connect my application with knime(which is already running) for reading input data and execution of workflow.Are there any nodes that could help me in this work.
You can run any external application by using the External Tool Node.
To trigger the workflow from your applet, consider running KNIME in CLI mode, as described here. Make use of some workflow variables to set the input/output file path to your workflow as described in the given FAQ. A potential issue I see might be some latency caused by the startup time of the application.
[edit] After thinking for a second time, I have some doubts that it's at all possible to start a local application from an applet. In fact, I strongly assume, it's not possible :) If you want to stick to your applet, you could add some intermediate REST service though, with which the applet interacts. After submitting the input data, the server side triggers the workflow and returns the result. Or you switch to some standard Swing application instead.
It is possible to call KNIME in batch mode and pass over parameters as Flow Variables. These Flow Variables can be used to configure node dialogs, such as the File Reader (path to file) automatically. See e.g.:
http://tech.knime.org/node/20877
http://tech.knime.org/forum/knime-developers/setting-flow-variables-on-command-line
for details.
If you have a KNIME server running, then you can achieve what you want via the REST api. There is a fairly detailed introduction to doing that here - https://www.knime.org/blog/the-knime-server-rest-api
I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.
Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.
If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.