Тести
Мова сайту: Українська
Українська
English
Русский
Тести з програмування
Вхід
Реєстрація
Тести з програмування
Теорія
Сніпети
Статті
Головна
Android
Ціни
FAQ
Історія Cosmo
Правила та умови сервісу
Політика конфіденційності
Політика щодо файлів cookie
Зворотній Зв’язок
synchronized
:
Мова контенту: English
Русский
Which keyword is used to show that the method can not work with more than one thread at a time?
synchronized
What will be displayed? public class TestMethods{ public static void main(String[] args){ TestMethods test = new TestMethods(); Thread anotherThread = new Thread("Thread#2"){ public void run(){ staticMethod(); } }; anotherThread.start(); test.instanceMethod(); } public static synchronized void staticMethod(){ System.out.println("Running static method"); try{ Thread.sleep(1000); } catch (InterruptedException e){ System.out.println(Thread.currentThread().getName() + " interrupted!"); } System.out.println("Exiting static method"); } public synchronized void instanceMethod(){ System.out.println("Running instance method"); try{ Thread.sleep(1000); } catch (InterruptedException e){ System.out.println(Thread.currentThread().getName() + " interrupted!"); } System.out.println("Exiting instance method"); } }
synchronized
← Попередня
1
Наступна →
Зареєструйся Зараз
або
Підпишись на майбутні тести