• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Web Page to Excel Sheet

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Sheriff
Posts: 22268
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody noticed this post?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic