Is it safe to call a static synchronized method from unrelated classes?

I have a class that uses a method static synchronizedto make HTTP calls.

I also have ExecutorService.

There are several Runnable classes that call this method. The method will take URLs, POST / GET information and arguments and return either an error code if the response is not 200 or an XML string, which will be processed further by the Runnable class.

If multiple threads call this method after posting in ExecutorService, will that be okay? Unsuccessful?

What is the ideal way to handle multiple HTTP calls through ExecutorService?

+4
source share
3 answers

Any question about "thread safety" should be a question about mutable shared data. If your streams do not transmit mutable data, then there is no thread safety issue.

A mutable object or group of mutable objects in your program is a "Safe Stream" if it is impossible for the action of any one thread to put the object / group in a "bad" state that can be seen by other threads.

/ - (.. synchronized / ). , , , synchronized , , / , synchronized block, / "".


. , - "" , . , , - , .

static synchronized, , , "", , .

/ , , synchronized, .


, . , , , .

.

+2

, synchronize Java:)

.

Object-wise, .

+1

ExecutorService . .

ExecutorService , , , .

. .

0

All Articles