.[ ČeskéHry.cz ].

Laboratoř ČeskýchHer.cz - PasteBin

Vložit nový kód

ČeskéHry.cz - KOMUNITA HERNÍCH VÝVOJÁŘŮ

  1. Ladis
    17 dní
  2. 4dp
    29 dní
  3. signal slot v C++11
    84 dní
  4. ondra[sej]
    255 dní
  5. bez titulku
    263 dní
  6. bez titulku
    358 dní
  7. 4Vriskal
    436 dní
  8. Jatro
    452 dní
  9. 4destruct
    461 dní
  10. 4destruct
    462 dní
Link: http://nopaste.ceske-hry.cz/223332
Zaslal: ondra[sej]
Popis: Promenne instanci objektu
Jazyk: Java
Vloženo: 12.6.2011, 23:19
Stáhnout jako soubor
  1. public class ThreadTest extends Thread {
  2. int counter = 0;
  3. int increment;
  4. String name;
  5. private void printCounter() {
  6. System.out.println(name + ": " + counter);
  7. }
  8. private void increaseCounter() {
  9. counter += increment;
  10. }
  11. @Override
  12. public void run() {
  13. while (true) {
  14. printCounter();
  15. increaseCounter();
  16. try {
  17. Thread.sleep(1000);
  18. }
  19. catch(Exception e) {
  20. }
  21. }
  22. }
  23. public ThreadTest(String name, int inc) {
  24. this.name = name;
  25. this.increment = inc;
  26. }
  27. public static void main(String[] args) throws Exception {
  28. Thread a = new ThreadTest("A", 1);
  29. Thread b = new ThreadTest("B", 5);
  30. a.start();
  31. Thread.sleep(500);
  32. b.start();
  33. }
  34. }
  35.