Skip to content

Instantly share code, notes, and snippets.

@kasramp
Created August 4, 2020 22:07
Show Gist options
  • Save kasramp/aee0df2ab0d2be2bf9f3685933b8d75d to your computer and use it in GitHub Desktop.
Save kasramp/aee0df2ab0d2be2bf9f3685933b8d75d to your computer and use it in GitHub Desktop.
public class ThreadClass extends Thread {
private Thread thread;
private Vector<Mails> mailQueue = new Vector<Mails>();
public void start(Vector<Mails> mailQueue) {
if (thread == null) {
this.mailQueue = mailQueue;
thread = new Thread(this);
thread.start();
}
}
public void run() {
//Update share resource
synchronized (this) {
updateNoteBook();
}
// Other operation here
}
public static synchronized updateNoteBook() {
// Do whatever necessary
// The function can be called by one thread at the same time
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment