aspose file tools*
The moose likes Threads and Synchronization and the fly likes Multiple processes accessing single class data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multiple processes accessing single class data" Watch "Multiple processes accessing single class data" New topic
Author

Multiple processes accessing single class data

Minseong Kim
Greenhorn

Joined: Jun 28, 2010
Posts: 5
Hi.

so, what i want to do is..

for example,

if there is class1.java, class2.java and class.java,

and each java source file has main classes, and when compiled, load as an individual program.

let's say there is a deque in class.java.

what i want to do is to allow class1.java and class2.java accesses to the same deque(same memory space; i am not talking about creating instances; I want to access to the same memory) in class.java

how am I able to do this?

If this is possible, are class1.java and class2.java allowed to operate together? (I mean whether these two programs can work at the same time toward the deque.)




Thanks.



Unmesh Chowdhury
Ranch Hand

Joined: Jun 20, 2010
Posts: 45
You can try with the following three classes:





To test the above classes you may use the following fragment of code:


M.Sc. in CS, OCPJP6 93%
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Unmesh Chowdhury wrote:You can try with the following three classes:


Thats a nice example.

I was wondering if its possible to have the push logic in the push class and pop logic in the pop class and still access the shared resource. To answer my own question we could synchronize on the resource itself,
Something like
synchronized(commonResource){
push or pop logic
}

I assume thats what the original question was leaning towards.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

Yes, you can access the same memory. Java has a shared memory model.
See java doc for some information
and see Java and C++ example for an example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple processes accessing single class data