Basic Concept Problem

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

[857 byte] By [Dimpu1978a] at [2007-11-26 19:25:00]
# 1
A method can't be declared as abstract and synchronized.I don't understand the rest of the question.
kajbja at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 2

Thank you for your message. Sorry i did wrong

-> Base class

public abstract class test {

public abstract void readData();

}

-> Child class1

public class test1 extends test {

public Synchronized void readData() {

read state1;

read state2;

}

}

-> Child class2

public class test2 extends test {

public Synchronized void readData() {

read state3;

read state4;

}

}

If I use two readData methods of two childs in different threads. If both threads are executing simultaneously . Then what will happen. I mean one method should be bloked until another method finish.

i would like to know is that readData method will be Synchronized.

Regards,

Sashi

Dimpu1978a at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 3
a normal class can not have an abstract method,same here could not understand rest of the question
krishna_kanth83a at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 4
> a normal class can not have an abstract method,> > same here could not understand rest of the questionAnd where's the normal class with the abstract method?Manuel Leiria
manuel.leiriaa at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 5

methods are called based on which object the call is made.

If two threads are running and both are trying to execute the method on the same object, then one will have to wait till the other executes.

If the threads are calling methods on different objects,there will not be any kind of locking.

krishna_kanth83a at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 6
@manuelsorry , i guess i was just late ,i was replying to first post., where the class test1 which is a normal class has an abstract methodMessage was edited by: krishna_kanth83
krishna_kanth83a at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...
# 7

Hallo,

Thank you for your messages. As I already wrote that I did wrong in my first post. I am asking about second post. Below once again i am writing the code. So please give the answers for this post.

public Interface class test {

public void readData();

}

-> test1 class

public class test1 extends thread implements test {

public Synchronized void readData() {

System.out.println("read statement1");

System.out.println("read statement2");

}

public void run() {

readData();

}

}

-> test2 class

public class test2 extends thread implements test {

public Synchronized void readData() {

System.out.println("read statement3");

System.out.println("read statement4");

}

public void run () {

readData();

}

}

Now I think it is clear. I would like to know if this readData() method is Synchronized between test1 calss and test2 class.If not then let me know how can I make it Synchronized.

Keep in mind that test1 class readData() and test2 class readData() do not have same functionality.

If both threads are accessing readData() at same time, one thread should be blocked.

If this is also not clear, then I will write more in detail.

Thanks

Sashi

Dimpu1978a at 2007-7-9 21:48:39 > top of Java-index,Java Essentials,Java Programming...