File tree 11 files changed +26
-30
lines changed 11 files changed +26
-30
lines changed Original file line number Diff line number Diff line change 1
1
package ActiveObject .App ;
2
-
3
2
import ActiveObject .Models .Consumer ;
4
3
import ActiveObject .Models .Producer ;
5
4
import ActiveObject .Proxy ;
6
5
import ActiveObject .TimerRunnable ;
7
-
8
6
import java .io .FileNotFoundException ;
9
7
import java .io .FileOutputStream ;
10
8
import java .io .PrintStream ;
11
- import java .lang .reflect .Array ;
12
9
import java .util .ArrayList ;
13
- import java .util .Arrays ;
14
10
import java .util .List ;
15
11
import java .util .concurrent .Executors ;
16
12
import java .util .concurrent .ScheduledExecutorService ;
17
13
import java .util .concurrent .TimeUnit ;
18
14
19
15
public class Main {
20
16
public static void main (String [] args ) throws FileNotFoundException , InterruptedException {
21
- PrintStream out = new PrintStream (new FileOutputStream ("new_outputAO_sleep " + 1000 + ".txt" ));
17
+ PrintStream out = new PrintStream (new FileOutputStream ("outputAO_sleep_thread " + 2 + ".txt" ));
22
18
System .setOut (out );
23
- final int N = 100 ;
24
- final int capacity = 10000 ;
19
+ final int N = 2 ;
20
+ final int capacity = 5000 ;
25
21
List <Thread > prodList = new ArrayList <>();
26
22
List <Thread > consList = new ArrayList <>();
27
23
Proxy proxy = new Proxy (capacity );
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public void run() {
29
29
taskList .add (proxy .consume (random .nextInt (bufferLimit / 2 ) + 1 ));
30
30
31
31
try {
32
- Thread .sleep (1000 ); //give him some time to finish job
32
+ Thread .sleep (500 ); //give him some time to finish job
33
33
for (Iterator <Future > iterator = taskList .iterator (); iterator .hasNext ();){
34
34
Future task = iterator .next ();
35
35
if (task .isFinished ()){
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public void run() {
29
29
taskList .add (proxy .produce (random .nextInt (bufferLimit / 2 ) + 1 ));
30
30
31
31
try {
32
- Thread .sleep (1000 ); //give him some time to finish job
32
+ Thread .sleep (500 ); //give him some time to finish job
33
33
for (Iterator <Future > iterator = taskList .iterator (); iterator .hasNext ();){
34
34
Future task = iterator .next ();
35
35
if (task .isFinished ()){
Original file line number Diff line number Diff line change 1
1
package AsyncPC .App ;
2
2
3
- import AsyncPC .Logic .Models .SecSolutionBetter .ConsumerQ2 ;
4
- import AsyncPC .Logic .Models .SecSolutionBetter .ProducerQ2 ;
5
- import AsyncPC .Logic .Utils .SecSolutionBetter .Buffer ;
6
- import AsyncPC .Logic .Utils .SecSolutionBetter .PCMonitorAsyncQueue2 ;
3
+ import AsyncPC .Logic .Models .FinalSolution .ConsumerQ2 ;
4
+ import AsyncPC .Logic .Models .FinalSolution .ProducerQ2 ;
5
+ import AsyncPC .Logic .Utils .FinalSolution .Buffer ;
6
+ import AsyncPC .Logic .Utils .FinalSolution .PCMonitorAsyncQueue2 ;
7
7
8
8
import java .io .FileNotFoundException ;
9
9
import java .io .FileOutputStream ;
14
14
import java .util .concurrent .ScheduledExecutorService ;
15
15
import java .util .concurrent .TimeUnit ;
16
16
17
- public class MainQ2 {
17
+ public class MainFinal {
18
18
19
19
public static void main (String [] args ) throws FileNotFoundException {
20
- PrintStream out = new PrintStream (new FileOutputStream ("new_outputAsync_sleep " + 1000 + ".txt" ));
20
+ PrintStream out = new PrintStream (new FileOutputStream ("outputAsync_sleep_thread " + 2 + ".txt" ));
21
21
System .setOut (out );
22
- int capacity = 10000 ;
23
- int threadAmount = 100 ;
22
+ int capacity = 5000 ;
23
+ int threadAmount = 2 ;
24
24
List <Thread > prodList = new ArrayList <>();
25
25
List <Thread > consList = new ArrayList <>();
26
26
PCMonitorAsyncQueue2 pcMonitorAsync = new PCMonitorAsyncQueue2 (capacity );
Original file line number Diff line number Diff line change 7
7
import java .util .ArrayList ;
8
8
import java .util .List ;
9
9
10
- public class Main {
10
+ public class MainFst {
11
11
public static void main (String [] args ) {
12
12
final int capacity = 50 ;
13
13
final int producerAmount = 10 ;
Original file line number Diff line number Diff line change 7
7
import java .util .ArrayList ;
8
8
import java .util .List ;
9
9
10
- public class MainQ {
10
+ public class MainSec {
11
11
public static void main (String [] args ) {
12
12
int capacity = 100 ;
13
13
int threadAmount = 10 ;
Original file line number Diff line number Diff line change 1
1
package AsyncPC .App ;
2
2
3
- import AsyncPC .Logic .Utils .SecSolutionBetter .PCMonitorAsyncQueue2 ;
3
+ import AsyncPC .Logic .Utils .FinalSolution .PCMonitorAsyncQueue2 ;
4
4
5
5
public class TimerRunnableAsync implements Runnable {
6
6
private PCMonitorAsyncQueue2 monitor ;
Original file line number Diff line number Diff line change 1
- package AsyncPC .Logic .Models .SecSolutionBetter ;
1
+ package AsyncPC .Logic .Models .FinalSolution ;
2
2
3
- import AsyncPC .Logic .Utils .SecSolutionBetter .Buffer ;
4
- import AsyncPC .Logic .Utils .SecSolutionBetter .PCMonitorAsyncQueue2 ;
3
+ import AsyncPC .Logic .Utils .FinalSolution .Buffer ;
4
+ import AsyncPC .Logic .Utils .FinalSolution .PCMonitorAsyncQueue2 ;
5
5
6
6
import java .util .ArrayList ;
7
7
import java .util .Random ;
@@ -32,7 +32,7 @@ public void run() {
32
32
for (Integer element : elementsToConsume )
33
33
this .buffer .takeElement (element );
34
34
this .pcMonitorAsyncQueue .takeFromEnd (elementsToConsume );
35
- Thread .sleep (1000 );
35
+ Thread .sleep (500 );
36
36
}catch (InterruptedException e ){
37
37
e .printStackTrace ();
38
38
}
Original file line number Diff line number Diff line change 1
- package AsyncPC .Logic .Models .SecSolutionBetter ;
1
+ package AsyncPC .Logic .Models .FinalSolution ;
2
2
3
- import AsyncPC .Logic .Utils .SecSolutionBetter .Buffer ;
4
- import AsyncPC .Logic .Utils .SecSolutionBetter .PCMonitorAsyncQueue2 ;
3
+ import AsyncPC .Logic .Utils .FinalSolution .Buffer ;
4
+ import AsyncPC .Logic .Utils .FinalSolution .PCMonitorAsyncQueue2 ;
5
5
6
6
import java .util .ArrayList ;
7
7
import java .util .Random ;
@@ -32,7 +32,7 @@ public void run() {
32
32
for (Integer element : elementsToProduce )
33
33
this .buffer .setElement (random .nextInt (this .buferLimit / 2 ) + 1 , element );
34
34
this .pcMonitorAsyncQueue .insertOnEnd (elementsToProduce );
35
- Thread .sleep (1000 );
35
+ Thread .sleep (500 );
36
36
}catch (InterruptedException e ){
37
37
e .printStackTrace ();
38
38
}
Original file line number Diff line number Diff line change 1
- package AsyncPC .Logic .Utils .SecSolutionBetter ;
1
+ package AsyncPC .Logic .Utils .FinalSolution ;
2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
Original file line number Diff line number Diff line change 1
- package AsyncPC .Logic .Utils .SecSolutionBetter ;
1
+ package AsyncPC .Logic .Utils .FinalSolution ;
2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .Queue ;
You can’t perform that action at this time.
0 commit comments