이 코드는 main에 여러 개의 오류를줍니다. 누군가가 나에게 뭐가 잘못 됐는지 말해 줄 수 있니? 첫 번째 포스터이므로 부드럽게하십시오.멀티 스레딩에 잠긴 java
질문은 램프를 만들 소비자 및 생산자 스레드를 만드는 것입니다.
StartProducer startproducer = new StartProducer();
가 Consumer1
생성되는 : 두 소비자는
public class ProducerConsumerTest{
public static void main(String[] args){
StartProducer startproducer = new StartProducer();
System.out.println("Start producer calling");
startproducer.start();
}
}
class StartProducer extends Thread{
Screw screw = new Screw();
Base base = new Base();
Stand stand = new Stand();
Socket socket = new Socket();
LightBulb lightbulb = new LightBulb();
int screws = screw.screwcount;
int bases = base.basecount;
int stands = stand.standcount;
int sockets = socket.socketcount;
int lightbulbs = lightbulb.bulbcount;
Consumer1 consumer1 = new Consumer1();
Consumer2 consumer2 = new Consumer2();
public synchronized void run(){
System.out.println("producer test");
screw.start();
base.start();
stand.start();
socket.start();
lightbulb.start();
boolean possible = possibleToBuildLamp(screws,bases,stands,sockets,lightbulbs);
if(possible == true){
consumer1.start();
consumer2.start();
}
}
private boolean possibleToBuildLamp(int screws, int bases, int stands,
int sockets, int lightbulbs) {
if(screws>=4 && bases>=1 && stands>=1 && sockets>=3 && lightbulbs>=3){
return true;
}
else return false;
}
}
class Screw extends Thread{
public int screwcount;
public synchronized void run(){
while(true){
if(screwcount>=0 && screwcount<7){
screwcount++;
}
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Base extends Thread{
public int basecount;
public synchronized void run(){
while(true){
if(basecount>=0 && basecount <2){
basecount++;
}
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Stand extends Thread {
public int standcount;
public synchronized void run(){
while(true){
if(standcount>=0 && standcount<2){
standcount++;
}
}
}
}
class Socket extends Thread {
public int socketcount;
public synchronized void run(){
while(true){
if(socketcount>=0 && socketcount<7){
socketcount++;
}
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class LightBulb extends Thread {
public int bulbcount;
public synchronized void run(){
while(true){
if(bulbcount>=0 && bulbcount<4){
bulbcount++;
}
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Consumer1 extends Thread {
ProducerConsumerTest test = new ProducerConsumerTest();
StartProducer start = new StartProducer();
public synchronized void run(){
while(true){
Screw screw = new Screw();
Base base = new Base();
Stand stand = new Stand();
Socket socket = new Socket();
LightBulb lightbulb = new LightBulb();
screw.screwcount-=4;
base.basecount-=1;
stand.standcount-=1;
socket.socketcount-=3;
lightbulb.bulbcount-=3;
System.out.println("one lamp made");
start.notify();
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Consumer2 extends Thread {
ProducerConsumerTest test = new ProducerConsumerTest();
StartProducer start = new StartProducer();
public synchronized void run(){
while(true){
Screw screw = new Screw();
Base base = new Base();
Stand stand = new Stand();
Socket socket = new Socket();
LightBulb lightbulb = new LightBulb();
screw.screwcount-=4;
base.basecount-=1;
stand.standcount-=1;
socket.socketcount-=3;
lightbulb.bulbcount-=3;
System.out.println("One lamp made");
start.notify();
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
* "처음으로 포스터 이렇게 부드럽게하십시오"* - 부드럽게 : "이 코드는 메인에 여러 개의 오류가 있습니다"라고 말하면서 오류가 무엇인지 또는 적어도 오류의 종류는 무엇인지 말해야합니다 아르. –