Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web Page to Excel Sheet

 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have to read data from a web page and copy it to an Excel sheet 3 times in a day and that all should be done automatically at specified time daily.
On the part of writing data to sheet I am using Apache POI and for automating the process at specific time I am using Timer class and it's methods.
I have gone through documentation for Timer class and used some versions of schedule() method defined there but on initial testing with println method I was not able to get satisfactory results.also I am not getting how to automate the task many times in a single day at specified timings.
I am pasting initial testing code here.

URLReader.java


MyTimer.java


also suggest if there can be a better way in comparison of Timer and TimerTask using which I can interact with POI . I have heard about "Quartz",also Windows scheduling service or cronjobs should not be used acc. to my requirement.


 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to schedule something 3 times a day, then the interval should be 8 hours (assuming an even spacing). What interval do you think "1000*365*24*7*60*60" represents? The presence of both "7" and "365" by itself should make you suspicious.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to schedule() method defined in Timer class, "1000*365*24*7*60*60" is total timespan for which task should be run(As explaind by link and what I have got).



schedule(TimerTask task, long delay, long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.


Link

There are fair chances that I would have made a mistake in choosing the right version of schedule method because definitions given in link seem to be little bit confusing.

Also I want that business logic should be performed on fixed delay of 3 hours during my office hours starting at 10:15 AM 3 times in a day.



 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What interval do you think "1000*365*24*7*60*60" represents? The presence of both "7" and "365" by itself should make you suspicious.

Another warning: that value is mathematically larger than Integer.MAX_VALUE so it will overflow. The result is probably even negative. The values should be turned into longs, or at least the first one: 1000L*365*24*7*60*60. Because the first one is a long the entire result will be a long and the value will not overflow.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to schedule() method defined in Timer class, "1000*365*24*7*60*60" is total timespan for which task should be run

No. It's the period between Task invocations. (Repeated Tasks run forever, or until the web app is terminated, whichever comes first.)

Also I want that business logic should be performed on fixed delay of 3 hours during my office hours starting at 10:15 AM 3 times in a day.

One approach would be to schedule a Task to run at, say, 10 AM each day which then creates 3 worker Tasks to run in 0:15h, 3:15h and 6:15h for non-repeating execution. Another approach would be to schedule 3 worker Tasks that run at 10:15, 13:15 and 16:15 each day repeatedly.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally I was able to write business logic.Here is the code snippet given below.
But I am facing a new problem now.



Here I have hardcoded the value of k i.e. row no. but I am not getting how to move the cursor to new line of Excel sheet at each run of program means data should be inserted in a new row on each run of program such that value of k should be increased to one more on each run of program.


>
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody noticed this post?
 
Aby Kuriakose
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a condition for checking the empty row before the for loop begins and assign the row value to intialize "k" in for loop.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic