Search:

Type: Posts; User: hellokitty25

Search: Search took 0.39 seconds.

  1. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi To cut short:

    What I want is the Ball class which extend Thread and the main method which start the thread.
    The output should be given that the numOfball initial value is 2 and after 2 it will...
  2. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi In my main program the inital value is 2 and I need to pass it to the class as shown below:
    public static void main(String[] args)
    {
    Ball [] ball = new Ball[5];
    int numOfball = 2;
    for (int i...
  3. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi all instances should shared one value.That is the numOfball will be shared by the instances each time a thread is started.
  4. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    If I do not set it,is there any other ways to get the numOfball in the main program?
  5. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi in the main program there is a return value which will change the value
    numOfball= ball[i].getNum();
  6. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    public class TestBall
    {

    public static void main(String[] args)
    {
    Ball [] ball = new Ball[5];
    int numOfball = 2;

    for (int i = 0; i < ball.length; i++)
    {
  7. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi all

    What I am trying to do is this:

    The output should be:
    Ball0 throw
    Ball6 throw
    Ball7 throw
    Ball8 throw
    Ball0 return
  8. How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Hi all

    Suppose I have a main method that do the following:
    Ball [] ball = new Ball[5];
    private int numOfball = 10;

    for (int i = 0; i < ball.length i++)
    {
    ball[i] = new...
  9. Re: Synchronized a integer variable in Java

    Hi

    I almost got the output. Just that as this is a thread, the numOfballs must be synchronized. Otherwise the numOfball will not be correct.
  10. Re: Synchronized a integer variable in Java

    Hi I am trying to create 10 objects of Myclass which extends Thread in the main class. The numOfball is passed to the Myclass objects and return to the main class.
    The numOfball must be...
  11. Re: Synchronized a integer variable in Java

    Hi

    What I am trying to achieved is that I will have 10 objects of Myclass which is a thread. The numOfball inside must not be overwrite.

    Regards
  12. Synchronized a integer variable in Java

    Hi all

    I am trying to synchronized an integer variable in java.

    An example is as below:

    class Myclass{
    private static int numOfball

    public synchronized void getBall()
Results 1 to 12 of 12