Abdul
Abdul

Reputation: 53

Interrupt in java thread

I have a vector storing String objects. I want to put a check on vector which must ensure that if new element is added an interrupt is called. How can i write interrupt service routine (If possible) in JAVA?

Upvotes: 1

Views: 121

Answers (1)

Farvardin
Farvardin

Reputation: 5424

a simple solution is to make a wrapper for your vector :

class MyVector {
  private Vector;

  public setVector(Vector v){
    this.vector = v;
  }

  public add(String s){
    intruptService();
    vector.add(s);
  }

  private intruptService(){
     //TODO
     your-code
  }

}

other more complicated solution is using Observer Pattern.

Upvotes: 2

Related Questions