473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

threading an poling in java

7
dear all i am quite new to java multithreading and i am trying to create a thread that read a byte array from a streaming thread that streams in an array of bytes withen 10 seconds my new thread should be able to read a data each secound and sleep for one secound and then read another deta and compare the them at the end
Jun 20 '07 #1
2 1432
JosAH
11,448 Expert 8TB
dear all i am quite new to java multithreading and i am trying to create a thread that read a byte array from a streaming thread that streams in an array of bytes withen 10 seconds my new thread should be able to read a data each secound and sleep for one secound and then read another deta and compare the them at the end
Think of a cookie jar as a shared resource. You and I both agree that when the lid
is not on the jar we simply wait until someone else gives us a push. You are a
cookie supplier and I am a cookie monster (I eat those cookies!). Only one of
us can grab the lid from that jar (we don't fight for it and we play it fair).

When I can grab the lid from that jar and I find a cookie, I'll eat it and put that
lid back on. If I don't find a cookie I simply put that lid back on and wait.

When you (the cookie producer) can grib the lid from that jar and you don't find
a cookie in there you put a cookie in the jar and put that lid back on. If you find
a cookie in the jar you just put that lid on the jar again.

Putting the lid back on that jar makes a lot of noise and activates anyone who
was waiting for that event.

Suppose we start with an empty jar and I was first. I open the jar, see nothing
and put the lid back on and wait. The you come: you find the closed empty jar
put a cookie in and close that jar again. I sort of wake up, find the lid on the
jar, open it and eat the cookie.

That lid is the mutex, which you own or not. The 'synchronized' keyword in java
is the analogy of that lid. If I don't find a cookie I wait. The Object's wait() method
is Java's equivalence of that. Putting that lid on that jar again (with a lot of noise)
is represented in Java by the Object's notify(All)() method.

That cookie represents the bytes written by the producer and consumed by me
the cookie monster: no cookie means no bytes written. A cookie in the jar is
equivalent to written an not yet consumed bytes. You and I are the two different threads.

Does that clarify things a bit?

kind regards,

Jos
Jun 20 '07 #2
pmakoi
7
thanks a lot for your response it sure did helped
Jun 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
12
by: Gurpreet Sachdeva | last post by:
I have written a code to figure out the difference in excecution time of a func before and after using threading... #!/usr/bin/env python import threading import time loops =
37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
13
by: Varun | last post by:
Hi Friends, Department of Information Technology, Madras Institute of Technology, Anna University, India is conducting a technical symposium, Samhita. As a part of samhita, an Online Programming...
1
by: Your Friend | last post by:
Hello All, I'm having issues capturing the output from a program while using threading. Program runs ok when I run without threading. Here's my Python code and the Java class that is called by...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.