• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple processes accessing single class data

 
Minseong Kim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try with the following three classes:





To test the above classes you may use the following fragment of code:
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Golebiowski
Ranch Hand
Posts: 213
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic