Java TimerTask ⌚

preview_player
Показать описание
Java timertask tutorial

#java #timertask #tutorial
Рекомендации по теме
Комментарии
Автор

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class Main {

public static void main(String[] args) {

// Timer = A facility for threads to schedule tasks
// for future execution in a background thread

// TimerTask = A task that can be scheduled for one-time
// or repeated execution by a Timer

Timer timer = new Timer();

TimerTask task = new TimerTask() {

int counter = 10;
@Override
public void run() {
if(counter>0) {
seconds");

}
else {
NEW YEAR!");

}
}
};

Calendar date = Calendar.getInstance();
date.set(Calendar.YEAR, 2020);
date.set(Calendar.MONTH, Calendar.DECEMBER);
date.set(Calendar.DAY_OF_MONTH, 31);
date.set(Calendar.HOUR_OF_DAY, 23);
date.set(Calendar.MINUTE, 59);
date.set(Calendar.SECOND, 50);
date.set(Calendar.MILLISECOND, 0);

//timer.schedule(task, 0);
//timer.schedule(task, date.getTime());
//timer.scheduleAtFixedRate(task, 0, 1000);
timer.scheduleAtFixedRate(task, date.getTime(), 1000);
}

}

BroCodez
Автор

The language is beautiful, your voice is clear and your teaching is fantastic keep it up bro

ramonoseiakoto
Автор

You are seriously amazing dude your tutorials alone have taught me Java

zachfornero
Автор

tysm! I was looking for a way to run code every 10 milliseconds while something else is running and this helped me a lot.

tedd_y
Автор

thanks . congratulations on 100k subscriber !

nawfalnjm
Автор

I tried to start the timer countdown on a certain input with an if statement. Idk if it didn't like how I was using scanner input, or if the timer stuff doesn't like being in an if statement, but I have yet to make it work how I want it. I'll keep learning, but any help is appreciated. It's not important, just me trying to get ahead of myself, but I like to know how things work. Thanks for the great tutorials!!!

cavemutt
Автор

Thank you! This solution was surprisingly hard to find on Google/YouTube

jaysonp
Автор

Really nice video.
I didn't see any documentation on Timer and I found your video
Really helped me understand everything.

flameyosflow_
Автор

thx bro. I'm wanting code with a "pretend" calendar, so user can jump ahead in time. this video got me started. lately, every java search I make in youtube ends with bro code :)

matthewbrightman
Автор

Best Java tutorial out there, thanks a lot Bro!

Makariush
Автор

Im brazilian programer and you helped me a lot, thanks bro

emanuelitalo
Автор

can you make videos on python projects? if you do, can you add one that has to do with object-oriented programming?

marioshusband