<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-web</artifactId>-->
<!--<version>1.3.5.RELEASE</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
public class Solution {
public static int totalCountSpeeches = 200000;
public static int soundsInOneSpeech = 1;
public static void main(String[] args) throws InterruptedException {
Politic ivanov = new Politic("Иванов"); //ivanov.join();
Politic petrov = new Politic("Петров");
Politic sidorov = new Politic("Сидоров");
// while (Politic.totalSounds < totalCountSpeeches*soundsInOneSpeech) {
// System.out.println("in main: total sounds -> "+Politic.totalSounds);
// System.out.println("in main: "+ivanov.getName()+" -> "+ivanov.getCountSpeaches());
// System.out.println("in main: "+petrov.getName()+" -> "+petrov.getCountSpeaches());
// System.out.println("in main: "+sidorov.getName()+" -> "+sidorov.getCountSpeaches());
// }
while (!(ivanov.finish | petrov.finish | sidorov.finish)) {}
System.out.println(ivanov);
System.out.println(petrov);
System.out.println(sidorov);
}
public static class Politic extends Thread {
public volatile static int totalSounds;
private volatile int countSounds;
public volatile boolean finish = false;
public Politic(String name) {
super(name);
start();
}
public synchronized void run() {
while (totalSounds < totalCountSpeeches * soundsInOneSpeech) {
countSounds++;
totalSounds++;
}
finish = true;
}
public int getCountSpeaches() {
System.out.println("in class: "+Politic.totalSounds);
System.out.println("in class: "+this.getName()+" -> "+countSounds);
return countSounds;
}
@Override
public String toString() {
return String.format("%s сказал речь %d раз", getName(), getCountSpeaches());
}
}
}
while (ivanov.getCountSpeaches() + petrov.getCountSpeaches() + sidorov.getCountSpeaches() < totalCountSpeeches) {
System.out.println(ivanov.getName()+" -> "+ivanov.getCountSpeaches());
public int getCountSpeaches() {
System.out.println("in class: "+this.getName()+" -> "+this.countSounds);
private int countSounds;