-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.gradle/ | ||
build/ | ||
caches/ | ||
.idea/ |
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
22 changes: 22 additions & 0 deletions
22
java-advanced-ru/multithreading-java/src/main/java/exercise/MaxThread.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
package exercise; | ||
|
||
import java.util.Arrays; | ||
|
||
// BEGIN | ||
public class MaxThread extends Thread{ | ||
private final int[] array; | ||
|
||
private int max; | ||
|
||
public MaxThread(int[] array) { | ||
this.array = array; | ||
} | ||
@Override | ||
public void run() { | ||
System.out.println("Thread " + this.getName() + " started"); | ||
max = Arrays.stream(array) | ||
.max() | ||
.orElse(0); | ||
System.out.println("Thread " + this.getName() + " finished"); | ||
} | ||
|
||
public int getMax() { | ||
return max; | ||
} | ||
} | ||
// END |
22 changes: 22 additions & 0 deletions
22
java-advanced-ru/multithreading-java/src/main/java/exercise/MinThread.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
package exercise; | ||
|
||
import java.util.Arrays; | ||
|
||
// BEGIN | ||
public class MinThread extends Thread { | ||
private final int[] array; | ||
|
||
private int min; | ||
|
||
public MinThread(int[] array) { | ||
this.array = array; | ||
} | ||
@Override | ||
public void run() { | ||
System.out.println("Thread " + this.getName() + " started"); | ||
min = Arrays.stream(array) | ||
.min() | ||
.orElse(0); | ||
System.out.println("Thread " + this.getName() + " finished"); | ||
} | ||
|
||
public int getMin() { | ||
return min; | ||
} | ||
} | ||
// END |