Java TimerTask ⌚

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 100

  • @BroCodez
    @BroCodez  Před 4 lety +43

    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) {
    System.out.println(counter+" seconds");
    counter--;
    }
    else {
    System.out.println("HAPPY NEW YEAR!");
    timer.cancel();
    }
    }
    };

    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);
    }
    }

    • @sreeshakv5405
      @sreeshakv5405 Před 2 lety

      Thanks

    • @joyceasante8292
      @joyceasante8292 Před rokem

      Practicing...
      import java.util.Calendar;
      import java.util.Timer;
      import java.util.TimerTask;
      public class Main{
      public static void main(String[]args){
      Timer timer = new Timer();
      TimerTask task= new TimerTask(){
      int counter = 10;
      @Override
      public void run(){
      if(counter>0) {
      System.out.println(counter+" seconds");
      counter --;
      }
      else{
      System.out.println("Interview with Priscilla");
      timer.cancel();
      }
      }

      };

      Calendar date = Calendar.getInstance();
      date.set(Calendar.YEAR,2023);
      date.set(Calendar.MONTH, Calendar.FEBRUARY);
      date.set(Calendar.DAY_OF_MONTH,19);
      date.set(Calendar.HOUR_OF_DAY,8);
      date.set(Calendar.MINUTE, 59);
      date.set(Calendar.SECOND,20);
      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);
      }
      }

  • @ramonoseiakoto2627
    @ramonoseiakoto2627 Před 2 lety +18

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

  • @zachfornero9371
    @zachfornero9371 Před rokem +2

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

  • @smburhan6323
    @smburhan6323 Před rokem +1

    Well Im a Fellow Bro 🤜🤛

  • @cavemutt
    @cavemutt Před 3 měsíci

    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!!!

  • @shaynazoedeguzman7418
    @shaynazoedeguzman7418 Před 2 lety +2

    Your tutorial is amazing! The best!

  • @tedd_y3423
    @tedd_y3423 Před 2 lety +1

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

  • @ShiroVK870
    @ShiroVK870 Před 4 lety +4

    Loving the java tutos 👍

  • @eugenezuev7349
    @eugenezuev7349 Před 2 měsíci

    the king of tutors

  • @matthewbrightman3398
    @matthewbrightman3398 Před 3 lety +1

    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 :)

  • @dougrattmann5791
    @dougrattmann5791 Před rokem

    You make the best java tutorials.

  • @guilhermeerafaeldourado247

    my man u are a true legend

  • @redwaroon6880
    @redwaroon6880 Před 3 lety +1

    Liked
    Commented
    Subscribed

  • @flameyosflow_4834
    @flameyosflow_4834 Před rokem

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

  • @vuchinh9989
    @vuchinh9989 Před 3 lety +1

    Bestt tutor with humour. Thanks alot!

  • @emanuelitalo5073
    @emanuelitalo5073 Před rokem

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

  • @raviratnakar3803
    @raviratnakar3803 Před 3 lety +1

    the greatest outro ever!

  • @Monster33336
    @Monster33336 Před 3 lety

    Very few Americans nowdays do Java because it's so hard, so thank you.

  • @efecantepe3990
    @efecantepe3990 Před 3 lety

    Nice video thank you.

  • @84_mostafaabbas88
    @84_mostafaabbas88 Před 3 lety +3

    perfect examples thanks a lot

  • @jaysonp9426
    @jaysonp9426 Před 2 lety

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

  • @girl6994
    @girl6994 Před 4 lety +7

    My Chinese teacher created a little game calls plane fight, and in the game he used timer task. To control enemy’s little plane’s speed.

  • @tulichakraborty4645
    @tulichakraborty4645 Před 3 lety

    This is fun..like it👍

  • @kimojumamil6121
    @kimojumamil6121 Před 3 lety +2

    This helped me a lot :) Thank you

  • @kemann3815
    @kemann3815 Před 2 lety +1

    Thanks an unimaginable amount, bro.

  • @Makariush
    @Makariush Před rokem

    Best Java tutorial out there, thanks a lot Bro!

  • @coolgolucool
    @coolgolucool Před rokem

    very helpful thank u

  • @nawfalnjm5699
    @nawfalnjm5699 Před 3 lety

    thanks . congratulations on 100k subscriber !

  • @mudzingwajonah7378
    @mudzingwajonah7378 Před 3 lety

    Sir I love your videos.

  • @frattekin1843
    @frattekin1843 Před 3 lety

    thank you bro very helpfull

  • @ejschoolaccount8299
    @ejschoolaccount8299 Před rokem

    Love it

  • @percivalgebashe4376
    @percivalgebashe4376 Před rokem

    nICE

  • @sergeyb6071
    @sergeyb6071 Před 4 lety +1

    I took a sneak peak at the explorer section to the left of your screen, I'm quite intrigued by the map project. It would be cool to do something with Google maps API. 🤩

    • @BroCodez
      @BroCodez  Před 4 lety +6

      That's a Dungeons & Dragons map generator for a hobby of mine, but a Google Maps program would be a fun project

    • @redaboukdir5678
      @redaboukdir5678 Před 2 lety

      ​@@BroCodez I like the fact that you do programming as a hobby, and this would explain why your tutorials are so great. Thank you for them btw.

  • @sreeshakv5405
    @sreeshakv5405 Před 2 lety

    Super

  • @marioshusband3700
    @marioshusband3700 Před 4 lety +4

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

    • @BroCodez
      @BroCodez  Před 4 lety +4

      I'll be switching back to Python soon. I wanted to add some more Java videos first due to popular demand

    • @marioshusband3700
      @marioshusband3700 Před 4 lety

      Bro Code ok thx

    • @girl6994
      @girl6994 Před 4 lety +1

      Bro Code I don’t understand his second part of his question. What does he mean by can you add one that has to do with OOP?

    • @BroCodez
      @BroCodez  Před 4 lety +1

      @girl中国 a Python project that uses Object-Oriented Programming

    • @angelcastineira2561
      @angelcastineira2561 Před 4 lety

      @@BroCodez no no no , no python, stay in Java LOL

  • @Heomi9905
    @Heomi9905 Před 3 lety +1

    Thank you so much!

  • @szaronaangel7725
    @szaronaangel7725 Před rokem

  • @sacredscrollshub
    @sacredscrollshub Před 3 měsíci

    Nice

  • @carloslozan856
    @carloslozan856 Před 2 lety

    Suporting to keep the channel running

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Před 2 lety

    Thanks

  • @SsjTestoKellerWaerter

    Frrr thx

  • @changeme1832
    @changeme1832 Před 2 lety

    Thank you very much 💕;)

  • @shashwathsk6880
    @shashwathsk6880 Před 3 lety

    nice video man

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 Před 2 lety

    thanks bro

  • @generalviewer8347
    @generalviewer8347 Před 4 lety

    dude i saw you subscribed to me.
    crazy thing is i have a java exam on tuesday! im really bad at it but i hope i make it.

  • @user-je3jj6fu7y
    @user-je3jj6fu7y Před 2 lety

    Nice work

  • @tonyadji2408
    @tonyadji2408 Před 2 lety

    helpful ! thanks

  • @walassi834
    @walassi834 Před 2 lety

    Hi!
    does this functions works as coolDown in games? (for skills, events...)

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Před rokem

  • @siavashnourmohammadi9189

    thank you bro .

  • @kishortiruke2695
    @kishortiruke2695 Před rokem

    hey this timer Task I used to update data in database....that through null point exception......you have any soluntion share me please.

  • @omanouras
    @omanouras Před 2 lety

    Brooooooooo

  • @manuelgonzalezpalafox2627

    Ly bro 11

  • @oguzhantopaloglu9442
    @oguzhantopaloglu9442 Před 3 lety +2

    great video but I guess useless for my specific project ;P

    • @BroCodez
      @BroCodez  Před 3 lety +2

      haha well you'll know for future projects

  • @sadasd7518
    @sadasd7518 Před 3 lety

    Thanks bro !!

  • @developerjunior446
    @developerjunior446 Před 3 lety

    Happy New Year !

  • @angelcastineira2561
    @angelcastineira2561 Před 4 lety

    thanks!

  • @aryanvashishtharollno.6919

    which software are u using ??

    • @BroCodez
      @BroCodez  Před 3 lety +1

      Eclipse IDE, I'm using dark theme

  • @troddennabcodm9246
    @troddennabcodm9246 Před 3 lety

    U deserve more views :(

  • @user-hu1lp3hh7u
    @user-hu1lp3hh7u Před rokem

    thanks cutie

  • @frankvalen2147
    @frankvalen2147 Před 3 lety

    How will I make it to execute every day by midnight

  • @lamias7712
    @lamias7712 Před 2 lety

    aaaannnd THANK YOUUUUU

  • @mechanicalpencil1016
    @mechanicalpencil1016 Před 3 lety

    what music did you use at the beginning of the video and in the intro?

  • @rodrigoqteixeira
    @rodrigoqteixeira Před 2 lety

    My birthday is 20th of june

  • @developerjunior446
    @developerjunior446 Před 3 lety

    10

  • @developerjunior446
    @developerjunior446 Před 3 lety

    1

  • @developerjunior446
    @developerjunior446 Před 3 lety

    6

  • @developerjunior446
    @developerjunior446 Před 3 lety

    3

  • @developerjunior446
    @developerjunior446 Před 3 lety

    8

  • @developerjunior446
    @developerjunior446 Před 3 lety

    4

  • @shervin9561
    @shervin9561 Před 2 lety

    Support

  • @developerjunior446
    @developerjunior446 Před 3 lety

    2

  • @developerjunior446
    @developerjunior446 Před 3 lety

    5

  • @siamax1
    @siamax1 Před rokem

    lol

  • @lightjack0540
    @lightjack0540 Před 4 lety +2

    You literally just subed to my channel with 0 Subs and 0 Videos. Do I know you? XD
    I dont think i ever stumbled across one of your Videos.
    Why do you know me and where did you find me? XD

    • @BroCodez
      @BroCodez  Před 4 lety

      I have no idea. Probably from one of a few Learn Java in X minutes videos

    • @lightjack0540
      @lightjack0540 Před 4 lety +2

      @@BroCodez Well, time to change your password. XD I didn't watch these kind of videos. I dont even Programm in java. I just do a little Visual Basic and Mcfunctions. XD

  • @honoredegg
    @honoredegg Před 2 lety

    85th. Thank you, ma Bro Sensei

  • @zari_723
    @zari_723 Před rokem

    hi

  • @developerjunior446
    @developerjunior446 Před 3 lety

    9

  • @tyjantefinn4791
    @tyjantefinn4791 Před 6 měsíci

    This has been deprecated :)

  • @developerjunior446
    @developerjunior446 Před 3 lety

    7