aspose file tools*
The moose likes Beginning Java and the fly likes scheduler task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "scheduler task" Watch "scheduler task" New topic
Author

scheduler task

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i need write the task to be schedule using window scheduler. How do i write the task? using servlet? or just a normal java method?

im using struts framework.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
It depends on the nature of your task. Since you're using Struts, must it be web-based? Or can you make do with a simple Java class? If a simple Java class suffice, then it would be simple, as per how you normally configure the scheduler.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i will be writing it as a standalone java application. But i dont know to start writing the function. Just as like normal, java class with void main? I have not done scheduler before. thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
If it is standalone application then you won't be able to use Struts or servlets.

But I'm not sure what you mean by "Windows scheduler". Java has its own scheduling system (based on java.util.Timer and TimerTask), but that is independent of any scheduling that happens within Windows. And it is active only as long as the JVM is active, so if you base this on an application, then that application will need to keep running permanently.


Ping & DNS - my free Android networking tools app
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think you can use Windows Task Scheduler to kick off any program. You could have it run "java MyProgram ..." but you probably want more control over paths and classpaths and such, so you could have Scheduler kick off a bat file that sets those variables and then runs "java MyProgram ..." And, yes, MyProgram would start in main() just like any other Java program.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
hi Stan James,

have another doubt hope you can help me to clarify. for the codes, i need to link to database to update some records, is it that i just as per normal have all those connection statement in the method? For those connection statement, can i call from other files?

In the bat file, i need to set the classpath all those. for the classpath it has to be a full path like, C:\work\lib\lib.jar? Can i do it like C:\work\lib\*.jar?

where should i place the bat file? same place as the class file?

thanks.

I tried:
set CLASSPATH=C:\j2sdk1.4.2\bin;C:\Documents and Settings\informix\Desktop\iadv\build\web\WEB-INF\lib\*.jar;
set PATH=C:\Documents and Settings\informix\Desktop\iadv\build\web\WEB-INF\classes\com\job;

java EnquiryScheduleTask

but i got this error:
Exception in thread "main" java.lang.NoClassDefFoundError: EnquiryScheduleTask (
wrong name: com/job/EnquiryScheduleTask)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
}
[ May 14, 2007: Message edited by: lynn fann ]
[ May 14, 2007: Message edited by: lynn fann ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scheduler task