File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Big Question in Synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Big Question in Synchronized" Watch "Big Question in Synchronized" New topic
Author

Big Question in Synchronized

Ernest Lee
Ranch Hand

Joined: Aug 20, 2001
Posts: 145
I have 2 methods in a class, let's say method A and method B.
If i want B to be stopped whenever A is doing something.. how can i implement it?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Only one method of a class is ever operating at a given time - at least I can't think of an example where this isn't the case (excepting threads and multiple objects of a class).
If you are talking about methods from two different objects of the same class, then you may wish to implement threads to get the job done. Take a look at Sun's Java Tutorial on Threads - especially the section on Synchronization.
Good Luck.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Only one method of a class is ever operating at a given time - at least I can't think of an example where this isn't the case (excepting threads and multiple objects of a class).
Errr... I assumed this was talking about multiple threads. Why else consider the synchronized keyword? It's certainly possible for two or more threads to have access to the same instance at the same time, and thereby run two different methods of that instance at the same time - or even the same method, from two different threads.
Or maybe you're referring to the fact that the processor is only acting on one thread at a time? This is true (unless you have multiple processors, which is certainly possible) but since either thread could interrupt the other at any time, the threads are generally thought of as running at the same time.
To be honest, this question doesn't seem like "Advanced Java" as much as "Basic Threads and Synchronization". Dirk's right - read up on the Sun tutorial. For further questions, we also have a Threads and Synchronization forum here at JavaRanch, which is the best place for this sort of thing. I'm moving this discussion there now.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Big Question in Synchronized
 
Similar Threads
book and release record in B&S
private main()
Servlet method call
protected Method service???
how is the flow in this JSP