How to write,compile and run Thread

i want to write a thread which runs at 12 o'clock night and then execute daily at 12 o'clock and execute some SQL query. plz send me the code which use extend method. and waht is the code to start it auttomatically at a perticular time

As an altnative, use the Calendar Object to calculate the next time you want to run, then sleep for that figure less the current time.
Something like:
public void run() {
  Calendar cal = Calendar.getInstance();
  Date now = Calendar.getTime();
  cal.set(Calendar.HOUR, 12);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  if(!cal.getTime().after(now))  // is it already after 12?
    cal.add(Calendar.DAY_OF_YEAR, 1);
  for(;;) {
    sleep(cal.getTime().getTime() - now.getTime());
    ... do your stuff
    cal.add(Calendar.DAY_OF_YEAR, 1);
    now = new Date();

Similar Messages

  • How do I compile and run Java programs on a Mac?

    To clarify my earlier post, I know that you can write java in any text editor but with the PC you compile and run everything through the MS DOS prompt, what is the Mac equivalent?

    See this question :-)
    http://forum.java.sun.com/thread.jsp?forum=54&thread=289574

  • How to develope, compile  and run soap service

    we want to implement the soap sevice in our concern.So its very diffcult to develope the soap program.I dont know about the soap service.please give me a input about soap and how to develope soap programs.Pls also give some sample programs and how to compile and run those programs.In our concern we are using UNIX operating system.
    Thanking you
    Yours faithfully
    Saran

    You should start by posting questions regarding web services on the correct forum ;)
    Next go to xml.apache.org and read the documentation regarding Apache Axis.
    You could also take a look at the Spring Framework's support for web services.
    You could even take a look at the Sun Web Service tutorials.
    The above resources have plenty of examples and sample code.

  • How should I compile and run my jdbc application ?

    I need help about how is the correct way for compile and run my application conecta.java using a driver postgresql-8.3-603.jdbc3.jar for connect to my database under Postgresql 8.1.4, . I have compiled as follow :
    javac -cp postgresql-8.3-603.jdbc3.jar conecta.java
    and I have compiled with sucessful obtaining conecta.class
    but when I try using :
    java conecta
    a message display an error :
    java.lang.ClassNotFoundException: org.postgresql.Driver
    I didn find the cause , I try modifing the classpath onto .bash_profile :
    # User specific environment and startup programs
    JDK_HOME=/usr/local/jdk1.5.0_01
    JAVA_HOME=/usr/local/jdk1.5.0_01
    PATH=$JAVA_HOME/bin:/usr/lib/pgsql/bin:$HOME/bin:$PATH:.
    CLASSPATH=$JAVA_HOME/lib/postgresql-8.3-603.jdbc.jar:$CLASSPATH.
    export PATH CLASSPATH JAVA_HOME JDK_HOME
    unset USERNAME
    but the message is the same . I have downloaded the driver into the same directory where is sited concecta.class and conecta.java . I don't understand why netbeans works fine runnning my application. I will be glad if anybody help to me.
    Thanks

    Miguel231152 wrote:
    I need help about how is the correct way for compile and run my application conecta.java using a driver postgresql-8.3-603.jdbc3.jar for connect to my database under Postgresql 8.1.4, . I have compiled as follow :
    javac -cp postgresql-8.3-603.jdbc3.jar conecta.javaActually, you probably don't need the JAR in the CLASSPATH to compile. You shouldn't refer to PostgreSQL classes in your code, just java.sql interfaces.
    and I have compiled with sucessful obtaining conecta.class
    but when I try using :
    java conectaGotta have the JAR in the CLASSPATH at runtime. That's why you get that exception, and that's always what it means.
    a message display an error :
    java.lang.ClassNotFoundException: org.postgresql.Driver
    I didn find the cause , I try modifing the classpath onto .bash_profile :
    # User specific environment and startup programs
    JDK_HOME=/usr/local/jdk1.5.0_01
    JAVA_HOME=/usr/local/jdk1.5.0_01
    PATH=$JAVA_HOME/bin:/usr/lib/pgsql/bin:$HOME/bin:$PATH:.
    CLASSPATH=$JAVA_HOME/lib/postgresql-8.3-603.jdbc.jar:$CLASSPATH.Useless. Java ignores CLASSPATH environment variable.
    export PATH CLASSPATH JAVA_HOME JDK_HOME
    unset USERNAME
    but the message is the same . I have downloaded the driver into the same directory where is sited concecta.class and conecta.java . I don't understand why netbeans works fine runnning my application. I will be glad if anybody help to me.
    ThanksUse the -classpath option at runtime. That'll fix it.
    %

  • How can I compile and run other java classes from within an application?

    Hello there everyone! I really hope that someone can help me. I am writing a program that must be able to compile and run other java classes that are in different files, much like development environments like Kawa or Forte allow you to do.
    There has to be a way of doing this ( I hope!! ), but i can't seem to find it!!
    I have tried using this command to compile:
    Runtime.getRuntime().exec ("c:\\programs\\javac className.java");
    ...and this one to run:
    Runtime.getRuntime().exec ("c:\\programs\\java className");
    ...but neither works!!! I can compile and run classes that are in the same file as my application, but I can't get it to work at all for files in different directories or files.
    PLEASE, PLEASE, PLEASE help me - i've run out of ideas, and i need this to be working in 3 days!!!
    Thank you very much for any help anyone can give me, I really appreciate it!! Thanks again!!
    Adrian ( ...in distress!! )

    public class JavaCompiler{
       public static void main(String[] args)throws Exception{ //sorry bout the laziness
          if(args == null || args.length != 1){
             System.out.println("Usage: java JavaCompiler MyClass.java");
             System.exit(0);
          String className = args[0];
          Runtime rt = Runtime.getRuntime();
          Process p = rt.exec("javac " + className); //consider setting cpath for this
          p.waitFor();
          //now try to run after it is done.
          p = rt.exec("java " + className.substring(0, (className.length() - ".java".length()));
          p.waitFor();
          //do some other stuff
    }This should get you going. You may consider looking into the System.getProperty() method in order to determine the type of OS it is running on in order to findo out what command to run. I know that the sun tool listed above is nice, but by my understanding the sun tools provided are not guaranteed to stay the same. I'm no expert on this matter, but that is one of the reasons there is no API documentation for those tools. Also, I don't believe those tools come packaged with the JRE. (Of course if you are making an IDE it will be expected that the user has an sdk installed. Good luck with figuring this thing out.

  • How can i compile and run javatv ri on linux platform

    hi,
    can any one plz help me what is the requirement to execute javatv reference implementation on linux and what are the steps i should followand, and any commands required
    thx in adv

    See this question :-)
    http://forum.java.sun.com/thread.jsp?forum=54&thread=289574

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • How to compile and run PRO*C programs in Linux

    Hi all,
    This is my first post in this forum.
    I have Oracle 9i installed in linux platform .
    How can i compile and run Pro*C programs in linux.(i mean any commands or procedure to run these programs)
    please help me in this regard.
    Thanks in advance,
    Trinath Somanchi,
    Hyderabad .

    (1) How to compile the Pro*c program U got to have a makefile to compile a Pro*c program. It helps u in compiling and creating an excutable. Once U have created a makefile , just call "make" and it will do the compilation and create the executable as well.
    For a sample makefile visit
    http://asktom.oracle.com/~tkyte/proc_makefile/
    (2) How to run the Pro*c program ? and Once U have created an executable, U shall call that directly as any other linux command. Make sure U have the permissions to run the executable. If not give the permissions using chmod 777 executable
    (3)How to get the output of the program ?Question 2 and 3 are the same. I mean running and getting a output are the same

  • How to compile and run the servelt

    how to the compile and run the servlet programmes and how should i deploy them
    and is there any site for the tomcat server free download

    your first question is too general. you'll need a tutorial a Hello World on a servlet...google it.
    for the second one go to [http://tomcat.apache.org]

  • How to Set up the  variables and others to compile and Run Java Programs

    Hello,
    I have just downloaded the jdk1.6.0_07 and jre1.6.0_07 and installed it in C:\Program files\Java in my Windows XP ,So please tell me how to sett up the enviroment variables etc to compile and run Java Programs from Command Prompt.
    thanks

    To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:
    1. Click Start > Control Panel > System on Windows XP or Start > Settings > Control Panel > System on Windows 2000.
    2. Click Advanced > Environment Variables.
    3. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
    C:\Program Files\Java\jdk1.6.0_<version>\bin

  • How to compile and run java files on a mac using command line?

    can someone tell me or link me to some article on how to compile and run java files from command line on a mac? I have mac OS X leopard

    What do you mean by "where to put them" ? What do you want to put anywhere ?
    Have you read Peter's comment in brackets ? Perhaps you have a classpath problem ?
    Edited by: Michael_Knight on Aug 31, 2008 4:23 AM

  • How to compile and run package programs in Java

    Hi,
    I want to know how to compile and run the package programs in Java using -d. instead of creating the package folder manually.
    eg:
    package Test;
    class test1
    public void disp()
    //Any code;
    I want to compile this without creating the folder ' Test ' manually. that is if we use -d with javac the Test folder will be created automatically. I need the format of -d
    could anyone please help me.
    Thanks in Advance ,
    Ambika

    My program Test.java in F:\Tomcat5\webapps\Ambika\WEB-INF\Classes. I compiled in the format below. I got like this. What should I do for this? But yesterday I compiled like this only, It compiled and the folder com\cert\Test.class is created. Today again I compiled the pgm after deleting the already created folder 'com\cert', I got the error like this.
    I've given my pgm and the thing I've got when I compiled it.
    Test.java
    package com.cert;
    public class Test
         public void display()
              System.out.println("Hai");
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>javac -d F:\Tomcat5\webapps\Ambika\WEB-INF\Classes\Test.java
    javac: no source files
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>
    Plz help me.
    thanks in advance
    Ambika

  • How to compile and run a java program?

    I am getting this error message, what to do?
    Exception in thread "main" java.lang.NoClassDefFoundError:
    Thanks for you help.
    Ajay

    Hello,
    I believe that this error is caused because when you
    compile and run a java program, you have to use the
    same name that is next to public class. For example,
    the program name is next to the word public class.
    For example, if a program began like this:
    public class Concat
    then the name of the program in this case is Concat
    and when you compile it you type: javac Concat.java
    when you run it type: java Concat
    depending on the name of your program.and depending on whether the class is in a package. And depending on what directory you are currently in.
    Also depending on if you set your class path you might
    have to type the above like this: jdk1.2.1\bin\javac
    Concat.java to compile, and to run you would have to
    type jdk1.2.1\bin\java Concat where you would replace
    Concat with the name of your program and replace
    jdk1.2.1 with the name of your version of java, that
    is again if you do not have your classpath set. Hope
    this helps.Your examples have nothing to do with whether the CLASSPATH is set--only with whether the PATH is set. And, it may not be jdkXXX\bin. The path to the JDK (in this case, to javac and java executables) could be anything. Classpath should be set on the command line. The OP probably did NOT set a classpath on the command line (preferred), or in the environment variables.
    Also, make sure you did not forget to put:
    public static void main(String[ ] args)
    on the line underneath the line where it says "public
    class Concat" where Concat is the name of your
    program. Again, I hope this helps.Irrelevant (with the info we have from the OP so far). The error says that the JVM can't even find the class--not that the class doesn't have a main. The "main" referred to in the error message is within the JVM itself.
    OP: Did you fix your problem? If not, what directory are your files in? Are they in a package? What command are you typing to get that error? That is, please tell us your entire command line.

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How to compile and run java program at command console

    hi there
    can anyone tell me how to compile and run a java program at command console? I have installed JRE 1.3.1, and also have installed JBuilder 5 if it helps.

    try this
    System.out.println("Enter your Name : ");
    BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) );
    String s = console.readLine();
    System.out.println("Hello : "+ s+" !" );

Maybe you are looking for

  • Inspire P5800 5.1

    wonder if anyone can help me , had the usual controller problems , that were thankfully sorted out by returning the set to the shop n getting a replacement set of speakers .... why dont more people just do this? prob is .... can anyone tell me the Oh

  • Open in adobe reader option doesn't appear

    I am unable to open PDFs in safari on my iPad air. I have the most recent version of Adobe reader installed and am using iOS 8. When I click on the "open in" option, nothing happens. There is no "open in adobe reader" option that appears.

  • New paper available on the Forms OTN page (Best practices...)

    This is a great paper about "Best practices when Developing Applications with Forms 10gR2" http://www.oracle.com/technology/products/forms/pdf/BESTPRACTICES10GR2.pdf Very interesting. Francois

  • Start up Looping

    I got my Nexus 3 days ago, it had done a couple "weird" things but all of the sudden I was just going through it, still getting familiar with it, it started to reboot.  It went to to the Google start up, then went to the color wheel, vibrated,screen

  • Please help!  Simple problem, I'm sure...

    Hi All! I would love any help anyone could provide on this. I have shied away from defining my own classes with Actionscript cause it seems so complicated, but I would feel very triumphant and confident if I could get this to work with your help. I h