| Author |
Basic concept problem?
|
Sashi Gundoji
Greenhorn
Joined: Jan 30, 2007
Posts: 10
|
|
Hallo all, I need one basic information about below program. I would like to know is this really works. -> Base class public abstract class test { public Synchronized abstract void readData(); } -> Child class1 public class test1 extends test { public Synchronized abstract void readData() { read state1; read state2; } } -> Child class2 public class test2 extends test { public Synchronized abstract void readData() { read state3; read state4; } } If this way possible, then i would like to know is that readData method will be Synchronized. If one Daemon is calling child1 readData Method and another daemon is calling child2 readData simultaneously, then what will happen. thanking you Regards, Sashi
|
 |
Sidd Kulk
Ranch Hand
Joined: Feb 20, 2007
Posts: 152
|
|
|
This code wont even compile. A method cannot be defined as 'abstract' and 'synchronized' at the same time, because abstract means that the method doesn't posses a body, while synchronizing is related to method implementation.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24059
|
|
Yes, there are all sorts of reasons why the above won't compile, but I think what he's really after is something about the different child classes which each have a method, synchronized or not, that override a common synchronized method (it wouldn't need to be abstract.) The short answer is that inheritance has nothing to do with it. Each individual object has its own "lock" for synchronization. Two threads will be able to call readData() on any two distinct objects simultaneously with no interference, whether those two objects belong to the same class or to two different classes.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Basic concept problem?
|
|
|