2

I'm investigate about synchronized block and scheduling rules. I know that both methods are used to guarantee synchronous data. But I don't understand them, how they work. What are the advantage and disadvantage of synchronized and scheduling rules? I referd the instruction about scheduling rules here: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fruntime_jobs_rules.htm In this document, it represented about a rule as below:

We can fix this example by creating a simple scheduling rule that acts as a mutex (also known as a binary semaphore):

   class Mutex implements ISchedulingRule {
      public boolean isConflicting(ISchedulingRule rule) {
         return rule == this;
      }
      public boolean contains(ISchedulingRule rule) {
         return rule == this;
      }    }

Then, the rule is set into a object or method to control jobs. In this code, I don't see rule as well as how to check rule. And when is the scheduling rule or synchronized used?

Thank in advance

Hieu Tran Trung
  • 495
  • 1
  • 4
  • 10

1 Answers1

0

schedule and synchronization are used when threads need to access the same data. It would be a major problem if one thread reads data, mutates it, and before it can write the data back, another thread reads the data.

This cross-section needs to be carefully attended to to ensure only one process can access the shared resource at a time. Synchronization allows only one process at a time to utilize the resource (in a more advanced way, the synchronization can allow a pre-determined number of multiple accesses if so inclined; ie semaphores)

The schedule is used to address which order the threads can access (timing) the shared resource.

If a thread does not have access to a resource that another thread would, there is no reason to worry about synchronization as it is the only one using that resource

specific to your code snippet, it creates a mutex (which it clearly states) which allows access of the resource to only one process- the note above it calls it a binary semaphore, and for all intents-and-purposes, it works like one. However, java uses monitors in their pre-defined mutex locks; not semaphores.

Jason V
  • 623
  • 1
  • 10
  • 30
  • if you would like i can delve into process synchronization quite a bit more, but suffice it to say, that is more of an operating systems question. You should think of it as a 'black box' that you can use and it works. – Jason V Jul 11 '17 at 16:10
  • Schedule and synchronization are used when threads access the same data. Shedule can determine order of execution of threads, synchronization doesn't determine order of execution of threads. Is my understand right? – Hieu Tran Trung Jul 12 '17 at 01:14
  • that is correct, synchronization ONLY ensures that only the alloted number of processes (one in a binary format) can access the data. – Jason V Jul 12 '17 at 11:55