Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A thread calling a method on another thread

 
Griff Haldeman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't believe there is any notion of threads sharing stacks in Java.
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic