Results 1 to 8 of 8
  1. #1
    slb056010 is offline Member
    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    Default how do i schedule some task in java

    my java program need to check a txt file at 1 hour time and need to delete the content of txt file before checking the link. how can i solve these problem. please help thank you

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: how do i schedule some task in java

    What did you research so far?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    slb056010 is offline Member
    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    Default Re: how do i schedule some task in java

    i need to schedule my program an hour time

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: how do i schedule some task in java

    Yes but what did you research? What options did you find that you are uncertain about to pick one?

    Don't tell me you thought of something to do and then you just came here to be told how to do it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    slb056010 is offline Member
    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    Default Re: how do i schedule some task in java

    class Roads {
    public static void main(String[] arg) throws Exception {
    String web1 = "http://programme.rthk.org.hk/channel/radio/traffic_news.php";//UTF-8
    read1(web1);
    }


    public static void read1( String strURL ) {
    int chunksize = 4096;
    byte[] chunk = new byte[chunksize];
    int count;
    try {
    URL pageUrl = new URL(strURL );


    BufferedInputStream bis = new BufferedInputStream(pageUrl.openStream());
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("URL1.txt", false));
    System.out.println("read1() running " );
    while ((count = bis.read(chunk, 0, chunksize)) != -1) {
    bos.write(chunk, 0, count); // ????
    }
    bos.close();
    bis.close();

    System.out.println("Done");
    }catch (IOException e) {
    e.printStackTrace();
    }
    }

    }


    this is my java program i need to run this program a hour per one time and before run this program i need to clearn the content of the txt file

  6. #6
    slb056010 is offline Member
    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    Default Re: how do i schedule some task in java

    i had try time and timetask but i don't know how to use it .can help me?

  7. #7
    slb056010 is offline Member
    Join Date
    Aug 2013
    Posts
    7
    Rep Power
    0

    Default Re: how do i schedule some task in java

    import java.net.*;
    import java.io.*;
    import java.util.*;

    class Roads{

    public static void read1( String strURL ) {//get website
    int chunksize = 4096;
    byte[] chunk = new byte[chunksize];
    int count;
    try {
    URL pageUrl = new URL(strURL );

    BufferedInputStream bis = new BufferedInputStream(pageUrl.openStream());
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("URL1.txt", false));

    while ((count = bis.read(chunk, 0, chunksize)) != -1) {
    bos.write(chunk, 0, count);
    }
    bos.close();
    bis.close();

    }catch (IOException e) {
    e.printStackTrace();
    }
    }


    public static void main(String[] arg) throws Exception {
    final int start=3;
    int delay=0;
    int period=3600000;//start at an hour;
    final Timer timer = new Timer();
    final String web1 = "http://zh.wikipedia.org/wiki/Dsafas";//news website
    read1(web1);
    timer.scheduleAtFixedRate(new TimerTask(){//schedule work
    public void run(){
    System.out.print("Final");
    while(start!=0)//start to getwebsite per a hour
    read1(web1);
    }
    },delay,period);//start 0delay secnod, repeat an hour
    }
    }

    have any way to make it a better program? aslo i need to search chinese in a txt file can help?
    Last edited by slb056010; 08-19-2013 at 07:29 AM.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: how do i schedule some task in java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help with a Java Task!
    By DABBISH in forum New To Java
    Replies: 7
    Last Post: 09-04-2011, 04:14 PM
  2. Java Schedule program
    By jaysyshaw in forum New To Java
    Replies: 0
    Last Post: 01-13-2010, 12:07 AM
  3. Java Task
    By Sokox in forum NetBeans
    Replies: 4
    Last Post: 12-13-2009, 09:57 AM
  4. How to schedule a job in java
    By Malathi in forum Web Frameworks
    Replies: 4
    Last Post: 03-27-2009, 10:14 AM
  5. Replies: 0
    Last Post: 06-26-2008, 07:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •