devsda devsda - 1 year ago 87
Java Question

Why synchronized method is not included in interface

When I use

on a method in an interface, the compiler emits an error. Can you tell me why this happens?

What is the reason (logically) that
cannot be applied to a method on an

I tried to make an Interface over Threadpool in this link.
Help me to make Interface in my above code.

Answer Source

Because synchronized is an implementation detail. One implementation of the method might need to make the method synchronized, whereas another one might not need it. The caller doesn't care whether the method is synchronized or not. It's not part of the contract, which tells what the method does. Which synchronization technique, if any, is used to fulfill the contract is irrelevant.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download