Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Time in Java

Time in Java

Scheduled Pinned Locked Moved Java
questionjava
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    williamroma
    wrote on last edited by
    #1

    hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty

    L N 3 Replies Last reply
    0
    • W williamroma

      hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The usual method is to use a timer[^] of some type. You may even find a sample here[^].

      The best things in life are not things.

      1 Reply Last reply
      0
      • W williamroma

        hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty

        N Offline
        N Offline
        Nothing Natarajan
        wrote on last edited by
        #3

        Hai Williamroma you can use Thread Class to run your program continuously and use Thread.sleep(1000); method to wait for every 10 seconds. Within the if statement it exceeds 10 seconds you can display the "hi" message from your program

        E 1 Reply Last reply
        0
        • W williamroma

          hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          import java.util.Timer;

          public class TimerExample {

          public static void main(String[] args) {

          Timer timer = new Timer();

          long delay = 10000; // 10 seconds

          timer.schedule(new Task("object"), 0, delay);

          }

          }

          ***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****

          1 Reply Last reply
          0
          • N Nothing Natarajan

            Hai Williamroma you can use Thread Class to run your program continuously and use Thread.sleep(1000); method to wait for every 10 seconds. Within the if statement it exceeds 10 seconds you can display the "hi" message from your program

            E Offline
            E Offline
            Etienne Rached
            wrote on last edited by
            #5

            Just a small correction, the parameter of Thread.sleep is in milliseconds, so 1000 is 1 second while 10000 is 10 seconds it should be Thread.sleep(10000) :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups