Home arrow static arrow Java Programming [Archive] - Buyers and Sellers
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Buyers and Sellers
This topic has 7 replies on 1 page.

Posts:77
Registered: 10/16/03
Buyers and Sellers  
Jul 26, 2004 11:35 AM



 
Hi everyone,

I am quite new to java and would appreciate your help. Basically I have a number of buyers and sellers that I want to trade with each other is some good. The buyer and seller each have a behaviour and I want to simulate time by having time steps. I am not sure how to go about doing this. I know I have to use threads but I am not sure how:

1) to synchronize between buyers and sellers so that in each time step, the buyers and sellers do their behaviour.

2) to sychrnoize when say one seller is trying to sell to more than one buyer or one buyer is trying to buy from many sellers.

The Sellers behaviour is to initialise account, then after setting to price to serve buyers. If at the end of the time step it is still not broke, it goes to the beginning.

The buyers after setting account, query one or all sellers for prices, select seller with lowest price, purchase goods and the start again .

Any guidance on how to do this would be greately appreciated.
 

Posts:24,036
Registered: 2/3/03
Re: Buyers and Sellers  
Jul 26, 2004 12:13 PM (reply 1 of 7)



 
http://www.google.com/search?q=java+threads+tutorial&sourceid=opera&num=0&ie=utf-8&oe=utf-8
http://java.sun.com/docs/books/tutorial/essential/threads/
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
http://www.cs.clemson.edu/~cs428/resources/java/tutorial/JTThreads.html
http://www-106.ibm.com/developerworks/edu/j-dw-javathread-i.html
 

Posts:77
Registered: 10/16/03
Re: Buyers and Sellers  
Jul 26, 2004 12:25 PM (reply 2 of 7)



 
Thanks. I am now looking into that.

Any suggestions on how the market should run, i.e. how to achieve the behaviours. Shall I have two threads, one for buyer and one for seller and then have a test class then synchronizes between them? How do I synchronize buyer and seller threads within a time step of running the market?
 

Posts:24,036
Registered: 2/3/03
Re: Buyers and Sellers  
Jul 26, 2004 12:34 PM (reply 3 of 7)



 
This stands out to me: "I am not sure how to go about doing this. I know I have to use threads but I am not sure how".

I'm not convinced you know why you need Threads. Read through and do those tutorials. When you're through, think about how threads might be used in your application. You may find multithreading is not even necessary.
 

Posts:105
Registered: 6/8/04
Re: Buyers and Sellers  
Jul 26, 2004 12:36 PM (reply 4 of 7)



 
...why do you need to use multiple threads? If you're just running a simulation, it doesn't make sense to have the buyers and sellers operating independently in real-time.

Just have a for loop count through timesteps. Multiple threads would be a good idea if you wanted them to interact in realtime, but I don't really see the point if you basically just want them to take turns buying and selling.

Or maybe I just don't understand what you're trying to do well enough?
 

Posts:21,719
Registered: 98-02-20
Re: Buyers and Sellers  
Jul 26, 2004 12:38 PM (reply 5 of 7)



 
Maybe you're thinking of Producers and Consumers, which is a classic problem for threads.

Java can certainly handle something like this. Google for examples if you insist on going down this path.

%
 

Posts:957
Registered: 3/31/04
Re: Buyers and Sellers  
Jul 26, 2004 12:41 PM (reply 6 of 7)



 
queue
 

Posts:24,036
Registered: 2/3/03
Re: Buyers and Sellers  
Jul 26, 2004 12:43 PM (reply 7 of 7)



 
queue

Sherriff Rosco P. Coltrane?

(queue, queue, queue)
 
This topic has 7 replies on 1 page.