This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes A thread calling a method on another thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A thread calling a method on another thread" Watch "A thread calling a method on another thread" New topic
Author

A thread calling a method on another thread

Griff Haldeman
Greenhorn

Joined: Jul 01, 2011
Posts: 5
Is there a way for Thread 2 to call a method that will go on Thread 1's stack and interrupt whatever Thread 1 is currently doing?

Thread 1: Running happily along

Thread 2: Comes along and calls a method that will go on Thread 1's stack, NOT Thread 2's stack; method runs to completion; Thread 1 resumes what it was doing

Thanks!
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

I don't believe there is any notion of threads sharing stacks in Java.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Nope. Was that idea supposed to be a solution to some problem, or was it just a question out of general interest? If there was an actual problem involved, it would be better to just ask about that problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
And welcome to the Ranch

It is of course possible for methods running in two threads to call methods on a particular object simultaneously and interfere with each other. Which is why you need synchronisation or similar.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A thread calling a method on another thread
 
Similar Threads
MDB-concurrency , serializing and reentrant?
Message Driven Beans
heap memory
how to "control" the sequence of two threads ?
How does this actually solve Towers of Hanoi?