Results 1 to 1 of 1
Thread: A little push using Semaphones
- 03-08-2011, 02:23 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
A little push using Semaphones
Let me first explain the project: I have 1 chef 3 homers, (Producer-Consumer problem). The chef has an unlimited supply of 3 ingredients. Each homer has 1 of the 3 ingredients in unlimited supply, but needs 2 of the other ingredients to complete the donut. Each homer can take 2 of the ingredients he needs to complete the donut. I must use semaphores to complete the assignment.
This is the code I have come up with, but I am unable to get much further. Maybe someone can push me in the right direction.
Java Code://package donutchef; import java.util.LinkedList; import java.util.concurrent.Semaphore; import java.util.List; /** * * @author Telamon */ public class Donut { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Homer h1 = Homer.getInstance("Homer 1"); Homer h2 = Homer.getInstance("Homer 2"); Homer h3 = Homer.getInstance("Homer 3"); DonutChef dc1 = DonutChef.getInstance(); Table table1 = Table.getInstance(); table1.addCustomer(h1); table1.addCustomer(h2); table1.addCustomer(h3); table1.addChef(dc1); Thread Homer1 = new Thread(h1); Thread Homer2 = new Thread(h2); Thread Homer3 = new Thread(h3); Thread DonutChef1 = new Thread(dc1); } } class DonutChef implements Runnable { private DonutChef() { } public static DonutChef getInstance() { return new DonutChef(); } public void notifyChef(){ } public void run() { throw new UnsupportedOperationException("Not supported yet."); } } class Homer implements Runnable { private String name; private Homer () { } private Homer (String name) { this.name = name; } public static Homer getInstance(String name){ return new Homer(name); } private void makeDonut() { } private void eatDonut() { } public void run() { throw new UnsupportedOperationException("Not supported yet."); } } class Table { private static Semaphore dsHomer = new Semaphore(0); private static Semaphore fillingHomer = new Semaphore(0); private static Semaphore sprinklesHomer = new Semaphore(0); private List<Homer> Customers; private List<DonutChef> Chefs; private Table(){ Customers = new LinkedList<Homer>(); Chefs = new LinkedList<DonutChef>(); } public static Table getInstance(){ return new Table(); } public void addCustomer(Homer h){ Customers.add(h); } public void addChef(DonutChef donutChef){ Chefs.add(donutChef); } }
Similar Threads
-
Stack (push/pop/top)
By sehudson in forum New To JavaReplies: 1Last Post: 03-08-2011, 02:40 AM -
XML file and i want to push in specific URL through java thread
By naval gupta in forum Java ServletReplies: 1Last Post: 07-17-2009, 08:08 AM -
How to wrap words in checkbox,push buttons
By gunjan.raizada in forum SWT / JFaceReplies: 3Last Post: 08-05-2008, 12:24 PM -
Stack push/pop/peek operations
By Java Tip in forum Java TipReplies: 0Last Post: 01-29-2008, 09:03 AM -
SWT push button
By Java Tip in forum Java TipReplies: 0Last Post: 12-31-2007, 01:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks