• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java application for stock watching

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,
I have been designing a small java application to pick up scripts from stock market and watching them and wanted to intimate if price crosses our level. When I created single java file to watch, it is some what delay if there aremore stocks picked (taking time for parsing, checking conditions and all).

Now i thought of creating separate thread for each stocks. so i hope there wont be any delay and we get at right time.. Could you some one guide if there is any better way than this?

But here also i wanted to collected information for all stocks and wanted to display in single frame and it has to refresh every 10 seconds... Any idea or any better design than this or something like that would be great help..thanks in advance

Thanks
Bala
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding more Threads to handle different stock quotes could help improve speed, but there will be a limit based on other bottleneck situations (processor, network connection, etc...). So you would have to test and see. My thought would be to use a variable sized ThreadPool and a Queue with all the stock quotes in it. Each Thread in the Pool takes a stock, processes it, updates the current value, and puts it back at the end of the Queue. You can then quickly compare the number of Threads you need to most efficiently grab the data.

It may be that it just isn't fast enough. It depends on what you are using to get the data. You may think about using a service which provides a Market Data API for gathering the data. You may find it more efficient than whatever method you have now which requires parsing.

As for the display - keep that separate. You could have a SwingTimer which triggers a refresh of the screen. Collect all the stock quotes into a single list and the refresh simply iterates and displays the value. You might also think about using an Observable and have individual prices update when they get modified, rather than a period refresh. Either way, I would have a 'Data Transfer Object' - one for each quote being watched. The JFrame holds a list of all of them but only calls a 'get' method to retrieve values. Meanwhile each parsing task/thread knows about just one of the DTOs and uses a 'set' method to update the value.
 
Balasubramaniam Muthusamy
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve for your information. Since all threads are running in every seconds how can we put into single object and display them in JFrame. is should be synchronized?

Thanks
Bala
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there probably needs to be some synchronization involved. For the simple case, you could probably just synchronize get... and set... methods for the stock quote. There are other options (such as using volatile or Atomic references).
 
reply
    Bookmark Topic Watch Topic
  • New Topic