I apologize in advance for the length of the note, and the source code
included.
I posted earlier under the title "Double streams", where i wanted to
use an RMI object as a sort of proxy for two clients to exchange data
via streams. I kinda failed, but now i'm trying something new. This
doesn't work either, but this time i think someone might be able to
solve it, since i'm not adept at using threads and i think that's
where the problem is. :)
The source for ByteHolder and RemoteByteHolde r is included below. A
server is run, making a ByteHolder, BH, available via RMI.
Client A obtains the reference to BH, and passes this on to its
FooOutputStream , which extends OutputStream and implements the
write(int b) method by calling putByte(b) on BH.
Client B also gets BH, passes this to FooInputStream, which extends
InputStream and implements read() by calling getByte() on BH.
What i did to test was:
- run the server
- client A wraps the FooOutputStream in a PrintWriter, and
println("foo") is called on it
- client B wraps FooInputStream in a InputStreamRead er, which is
then wrapped in a BufferedReader, and readLine() is called on that
The data then goes, one byte at the time, from client A to client B.
Client A stops running, but Client B just sorta hangs around... in a
deadlock i presume. I can make it return and print out the read line
by doing one of two things:
- kill the server
- manually send a -1 to client B
When i've used streams before, i didn't have to send a -1 in order to
get the reading side to get on with it - it just happened magically. I
also don't understand why killing the server make things better...
Can anyone explain this or, as an alternative, suggest a better way to
exchange bytes via RMI. I just really wanted to make streams work. :)
Oh, another thing. To make the server available, i've made it Runnable
and in the run i have a while(true) loop, that makes the thread sleep
for a chunk of time. Maybe that is a problem, too?
Regards,
Carsten H. Pedersen
----------- SOURCE BELOW -------------
package streams.holder;
import java.rmi.Remote ;
import java.rmi.Remote Exception;
public interface RemoteByteHolde r extends Remote {
int getByte() throws RemoteException ;
void putByte(int b) throws RemoteException ;
}
....
package streams.holder;
import java.rmi.Remote Exception;
public class ByteHolder implements RemoteByteHolde r {
private int theByte;
private boolean stored = false;
public synchronized int getByte() throws RemoteException {
while(!stored) {
try {
wait();
} catch (InterruptedExc eption e) {
// TODO Auto-generated catch block
e.printStackTra ce();
}
}
System.out.prin tln("hb: get: "+theByte);
int i = theByte;
stored = false;
notifyAll();
return i;
}
public synchronized void putByte(int b) throws RemoteException {
while(stored) {
try {
wait();
} catch (InterruptedExc eption e) {
// TODO Auto-generated catch block
e.printStackTra ce();
}
}
System.out.prin tln("bh: put: "+b);
stored = true;
theByte = b;
notifyAll();
}
} 2 2926
"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader2.cyber city.dk... I posted earlier under the title "Double streams", where i wanted to use an RMI object as a sort of proxy for two clients to exchange data via streams. I kinda failed, but now i'm trying something new. This doesn't work either, but this time i think someone might be able to solve it, since i'm not adept at using threads and i think that's where the problem is. :)
If you don't get any answers for 1 or 2 days, try posting this to
comp.lang.java. programmer. There's a lot of people there who are familiar
with threading who don't read this newsgroup.
If you post there too early though, you get accused of multiposting.
- Oliver
Hi Carsten,
What does your readLine code look like?
Are you doing something like:
while ((line = readLine())!=nu ll) ...
"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader2.cyber city.dk... I apologize in advance for the length of the note, and the source code included.
I posted earlier under the title "Double streams", where i wanted to use an RMI object as a sort of proxy for two clients to exchange data via streams. I kinda failed, but now i'm trying something new. This doesn't work either, but this time i think someone might be able to solve it, since i'm not adept at using threads and i think that's where the problem is. :)
The source for ByteHolder and RemoteByteHolde r is included below. A server is run, making a ByteHolder, BH, available via RMI.
Client A obtains the reference to BH, and passes this on to its FooOutputStream , which extends OutputStream and implements the write(int b) method by calling putByte(b) on BH.
Client B also gets BH, passes this to FooInputStream, which extends InputStream and implements read() by calling getByte() on BH.
What i did to test was: - run the server - client A wraps the FooOutputStream in a PrintWriter, and println("foo") is called on it - client B wraps FooInputStream in a InputStreamRead er, which is then wrapped in a BufferedReader, and readLine() is called on that
The data then goes, one byte at the time, from client A to client B. Client A stops running, but Client B just sorta hangs around... in a deadlock i presume. I can make it return and print out the read line by doing one of two things: - kill the server - manually send a -1 to client B
When i've used streams before, i didn't have to send a -1 in order to get the reading side to get on with it - it just happened magically. I also don't understand why killing the server make things better...
Can anyone explain this or, as an alternative, suggest a better way to exchange bytes via RMI. I just really wanted to make streams work. :)
Oh, another thing. To make the server available, i've made it Runnable and in the run i have a while(true) loop, that makes the thread sleep for a chunk of time. Maybe that is a problem, too?
Regards, Carsten H. Pedersen
----------- SOURCE BELOW -------------
package streams.holder;
import java.rmi.Remote ; import java.rmi.Remote Exception;
public interface RemoteByteHolde r extends Remote { int getByte() throws RemoteException ; void putByte(int b) throws RemoteException ; }
...
package streams.holder; import java.rmi.Remote Exception;
public class ByteHolder implements RemoteByteHolde r {
private int theByte; private boolean stored = false;
public synchronized int getByte() throws RemoteException { while(!stored) { try { wait(); } catch (InterruptedExc eption e) { // TODO Auto-generated catch block e.printStackTra ce(); } }
System.out.prin tln("hb: get: "+theByte); int i = theByte; stored = false; notifyAll(); return i; }
public synchronized void putByte(int b) throws RemoteException { while(stored) { try { wait(); } catch (InterruptedExc eption e) { // TODO Auto-generated catch block e.printStackTra ce(); } }
System.out.prin tln("bh: put: "+b); stored = true; theByte = b; notifyAll(); }
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Duncan Grisby |
last post by:
Hi,
Does anyone know of a deadlock detector for Python? I don't think it
would be too hard to hook into the threading module and instrument
mutexes so they can be tested for deadlocks. I've googled around but I
haven't found anything.
Cheers,
Duncan.
|
by: Anita |
last post by:
Hi All,
Can multiple updates on one table using single
query generate deadlock ?
For example, at the same time, there are 2 users
run 2 queries as follows :
User1 runs :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab2 on tab1.no = tab2.no
|
by: Andrew Mayo |
last post by:
Here's a really weird one for any SQL Server gurus out there...
We have observed (SQL Server 2000) scenarios where a stored procedure
which
(a) begins a transaction
(b) inserts some rows into a table
(c) re-queries another table using a subquery which references the
inserted table (correlated or not)
|
by: Nigel Robbins |
last post by:
Hi There,
I'm getting a deadlock when I have two clients running the following statement.
DELETE FROM intermediate.file_os_details WHERE file_uid = ? AND obj_uid
There is a compound index on file_uid / obj_uid.
The isolation level is UR and I have set DB2_RR_TO_RS=YES.
Any thoughts why I'm getting the deadlock ?
|
by: mk |
last post by:
You probably suspect the answer, typically its 'yes'
deadlock can occur in any multithreaded application.
Even ones that employ static members. Commonly it occurs
when more than one thread tries to lock a resource that
another thread has already locked.
A workaround is to use the Monitor object's TryEnter
method, and pass a timeout value, if timeout occurs the
method returns false.
This pattern will save you no end of pain and...
| |
by: Zeng |
last post by:
Hi,
The bigger my C# web-application gets, the more places I need to put in the
tedious retrying block of code to make sure operations that can run into
database deadlocks are re-run (retried) 3-4 times and give up if after that
it's still in deadlock. I'm very sure that many experienced people out
there already deal with this issue somehow. Is there an alternative to it?
Thanks for your comments and suggestions.
|
by: Joe Weinstein |
last post by:
Hi.
create table joe(c1 integer not null, c2 integer not null)
Two sessions:
Session 1:
BEGIN TRAN
insert into joe (c1,c2) values (1,2)
|
by: Jonathan Amsterdam |
last post by:
I think there's a slight design flaw in the Queue class that makes it
hard to avoid nested monitor deadlock. The problem is that the mutex
used by the Queue is not easy to change. You can then easily get
yourself into the following situation (nested monitor deadlock):
Say we have a class that contains a Queue and some other things. The
class's internals are protected by a mutex M. Initially the Queue is
empty. The only access to the...
|
by: ThunderMusic |
last post by:
Hi,
We have a web application developped in asp.net (I think it's not relevant,
but well, it's so you know)... Yesterday, we received the following message
"Transaction (Process ID 69) was deadlocked on lock resources with another
process and has been chosen as the deadlock victim. Rerun the transaction. "
The thing is, the query was a simple select with inner joins between 3
tables (like select fields from table1 inner join table2......
|
by: Arun Srinivasan |
last post by:
Please correct me if I am wrong
1. no 2 processes can have exclusive lock on same object (by object,
same row or same table)
2. on deadlock incident between 2 processes only one of them will be
cancelled by db2 to let the other finish.
Now, can there be an instance where 2 processes have 'EXCLUSIVE LOCK'
on same table, and are waiting on the same 'EXCLUSIVE LOCK' held by
the other agent to be relinquished. They both are cancelled by db2...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |