This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson03.task01; | |
/* My first thread | |
Создать public static class TestThread - нить с помощью интерфейса Runnable. | |
TestThread должен выводить в консоль "My first thread". | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
TestThread task = new TestThread(); | |
new Thread(task).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson03.task02; | |
/* My second thread | |
1. Создать public static класс TestThread унаследовавшись от класса Thread. | |
2. Создать статик блок внутри TestThread, который выводит в консоль "it's static block inside TestThread". | |
3. Метод run должен выводить в консоль "it's run method". | |
*/ | |
public class Solution { | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson03.task03; | |
import java.util.ArrayList; | |
import java.util.List; | |
/* Список и нити | |
В методе main добавить в статический объект list 5 нитей SpecialThread - различных объектов. | |
*/ | |
public class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson03.task04; | |
/* Вывод стек-трейса | |
1. Создать таск - класс public static SpecialThread - на основании интерфейса Runnable | |
2. SpecialThread должен выводить в консоль свой стек-трейс. | |
Подсказка: main thread уже выводит в консоль свой стек-трейс. | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws InterruptedException { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson03.task05; | |
import java.util.Calendar; | |
import java.util.Date; | |
/* Поговорим о музыке? | |
1. Измените класс Violin так, чтоб он стал таском для нити. Используйте интерфейс MusicalInstrument | |
2. Реализуй необходимый метод в нити Violin. Реализация должна быть следующей: | |
2.1. Считай время начала игры - метод startPlaying(). | |
2.2. Подожди 1 секунду - метод sleepNSeconds(int n), где n - количество секунд. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson05.task01; | |
import java.util.ArrayList; | |
import java.util.List; | |
/* join | |
Подумайте, в каком месте и для какого объекта нужно вызвать метод join, чтобы результат выводился по-порядку | |
сначала для firstThread, а потом для secondThread. | |
Вызовите метод join в нужном месте. | |
Пример вывода: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson05.task02; | |
import java.util.ArrayList; | |
import java.util.List; | |
/* Horse Racing | |
Разберись, что делает программа. | |
Реализуй метод calculateHorsesFinished. Он должен: | |
1. Посчитать количество финишировавших лошадей и возвратить его. Используй метод isFinished(). | |
2. Если лошадь еще не пришла к финишу (!isFinished()), то: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson05.task03; | |
/* Продвижение на политических дебатах | |
1. Разберитесь, что делает программа. | |
2. Нужно сделать так, чтобы Иванов сказал больше всего речей на политических дебатах. | |
3. Подумай, какой метод можно вызвать у объекта ivanov, чтобы Иванов разговаривал, пока не завершится всё свободное время. | |
*/ | |
public class Solution { | |
public static int totalCountSpeeches = 200; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson05.task04; | |
/* Справедливость | |
1. Разберитесь, что делает программа. | |
2. Нужно сделать так, чтобы все мыши ели одновременно. | |
3. Подумай, какой метод позволяет альфа-самцу мыши есть первым, и почему остальные мыши ждут. | |
4. Удали вызов этого метода. | |
*/ | |
public class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level16.lesson05.task05; | |
/* Расставь вызовы методов join() | |
1. Разберитесь, что делает программа. | |
2. Расставь вызовы методов join() так, чтобы для каждой кошки выполнялось следующее: | |
2.1. Сначала кошка рожает котят. | |
2.2. Потом все котята вылазят из корзинки в произвольном порядке. | |
2.3. В конце кошка собирает их назад в корзинку. | |
2.4. Все события для одной кошки могут быть перемешаны с событями для другой кошки. | |
*/ |
OlderNewer