• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i run a program every hour from Java (Weekdays only)  RSS feed

 
Peter Khumalo
Greenhorn
Posts: 2
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a program which launches MS Word in Java Eclipse now i want it to launch MS Word every hour including the night (Weekdays only).

Below is my current working code:




It Currently opens MS Word for 20 seconds and closes it .
I want it to open MS Word every hour and after 20 seconds from that hour it should close it and it should do it everyday of the week, every hour day and night.
 
Tony lala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your try block your'e saying thread to sleep for 20 seconds. After that you kill the process. So yes it kills the process after 20 seconds.

I think you need a process like this :


 
Tim Moores
Saloon Keeper
Posts: 3896
91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use an OS-provided facility like cron or Windows Task Scheduler for this, rather than trying to keep a Java process running at all times.
 
Peter Khumalo
Greenhorn
Posts: 2
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to put it together:

So now i should have 2 classes:

and how should they look?
 
Campbell Ritchie
Marshal
Posts: 55774
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of you, welcome to the Ranch

I added code tags to your posts, and broke a long line, and doesn't it look better Always use the tags.
Tim is correct; you should not use Java® code at all. What is more, if you are opening Word®, you are using platform‑specific programming, which will probably only work on Windows®, so the Windows®‑specific solution would be correct.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!