File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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: 18669
    
    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: 39436
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A thread calling a method on another thread