473,418 Members | 2,023 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,418 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 1435
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:...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.