commit
a818b82674
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/TP2.iml" filepath="$PROJECT_DIR$/TP2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello World!"); // Display the string.
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package sweet;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Boulangerie {
|
||||||
|
private final ArrayList<Patisserie> sweets = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public synchronized void depose(Patisserie p) {
|
||||||
|
this.notify();
|
||||||
|
sweets.add(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public synchronized Patisserie achete() {
|
||||||
|
while(sweets.size() == 0) {
|
||||||
|
try {this.wait();} catch (InterruptedException ignored) {}}
|
||||||
|
Patisserie pat = sweets.get(0);
|
||||||
|
sweets.remove(pat);
|
||||||
|
return pat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void getStock() {
|
||||||
|
// TODO implement here
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package sweet;
|
||||||
|
import java.util.*;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Client implements Runnable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
public Client() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package sweet;
|
||||||
|
|
||||||
|
import sweet.Patisserie;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Gateau extends Patisserie {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
public Gateau() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package sweet;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Patisserie {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
public Patisserie() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package sweet;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Patissier implements Runnable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
public Patissier() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package world;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class threadWeaver {
|
||||||
|
private final List<Runnable> runners = new ArrayList<Runnable>();
|
||||||
|
private final List<Thread> managed = new ArrayList<Thread>();
|
||||||
|
public void addRunners(Runnable... runners){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void weave(){
|
||||||
|
for(Runnable r: runners){
|
||||||
|
managed.add(new Thread(r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
for(Thread t : managed){
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recover(){
|
||||||
|
for(Thread t : managed){
|
||||||
|
try {
|
||||||
|
t.wait();
|
||||||
|
}catch(InterruptedException ie){
|
||||||
|
System.out.println(ie.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
termina();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recover(Long timeout){
|
||||||
|
for(Thread t : managed){
|
||||||
|
try {
|
||||||
|
t.wait(timeout);
|
||||||
|
}catch(InterruptedException ie){
|
||||||
|
System.out.println(ie.getMessage());
|
||||||
|
}
|
||||||
|
managed.remove(t);
|
||||||
|
}
|
||||||
|
termina();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void termina(){
|
||||||
|
for(Thread t : managed){
|
||||||
|
System.out.println("Thread "+t.getName()+" has not stopped being cleaned up");
|
||||||
|
t.interrupt();
|
||||||
|
}
|
||||||
|
managed.clear();
|
||||||
|
runners.clear();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue