Line block



  • A table sitesThere is a table URL - urls

    url is processed in a way that, with a certain frequency, targets are set with the desired time of implementation (desired_timefor each url and by ScheduledThreadPool performed. Flow. AIn an endless cycle, check active url (flagged) url.active == 1 in the OBD system and, if necessary, a new task that will be processed by another flow (refer to such flows) B); or closes the open task because it was not able to take any flow B and the desired time desired_time It's over.

    Targets are expected to be achieved (when one of the streams is selected) B) BlockingQueue

    A situation where B Processed the task at a time when desired_time The task would have come to an end. Until the flow B Action to prepare for the transfer of the result to be retained in the OBD system (or post-processing) - desired_time It'll end. But the task has already been accomplished and cannot be considered as overdue. However, flow A at this point, it may be possible to check the OBD task and see that it is desired_time It's over. But since the result has not yet been recorded in the OBD system - status the actual performance not yet amended DONE and A may close the status task ADDLED (process) after B complete the processing post and the result will be retained in the OBD. The base will be here. the correct result, but with status ADDLED

    There's a flow. Cwhich plays the role of some colbec for B♪ If, task-processing B There was a mistake that prevented the task from being processed further, B Challenge C..that she would be closed with status. ERROR♪ And we have three un synchronized flows.

    It is clear that the challenge for other flows should be blocked when:

    • B Achieved and started the processing post until the end in the OBD
    • C retains ERROR status

    The monitors should be exactly as long as URL is processed. One monitor for all tasks of one URL.

    How can such locks be implemented?



  • I'm usually using a cash where I'm holding facilities for synchronization.

    Ehcache idLockingCache = ..... ;
    private Lock idLockingCacheLock = new ReentrantLock();
    

    public Object getLock(String key) {
    Element element = idLockingCache.get(key);
    if (element == null) {
    idLockingCacheLock.lock();
    try {
    element = idLockingCache.get(key);
    if (element == null) {
    element = new Element(key, new Object());
    idLockingCache.put(element);
    }
    } finally {
    idLockingCacheLock.unlock();
    }
    }
    return element.getObjectValue();
    }

    Use

    //key в вашем случае это либо id url-а из БД, либо сам URL
    Object lock = getLock(key);
    synchronized (lock) {
    //work
    }

    And you're synchronizing in all places.

    P.S. For distributed blocks, use Hazelcast IMap.(lockkey)/unlock(key)




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2