-2

I am implementing a project which requires all the tests to update on to a particular variable. Is there a way to implement a shared variable which can be accessed by all the threads (during the parallel testing using Maven)?

If so, please share your ideas with me?

jww
  • 97,681
  • 90
  • 411
  • 885
  • Possible duplicate: http://stackoverflow.com/questions/13582395/sharing-a-variable-between-multiple-different-threads – mjk Oct 05 '14 at 01:41

1 Answers1

1

First, define a class which contains such variable, or it could be inside your thread (derived) class as well.

class Particular {
    static int count=0;
    public static synchronized static inc(){
        count++;
    }
    public static synchronized int getCount(){
        return count;
    }
}

Then, you can access the count using Particular.inc(); or Particular.getCount(); More advanced, you could use Singleton design pattern to ensure thread-safe.

Nebula Era
  • 263
  • 2
  • 10