implement timer class consider web-based calendar in which the server hosting the calendar has to perform task when the next calendar event takes place (the task could be sending an email or short message service (smsyour job is to design facility that manages the execution of such tasks develop timer class that manages the execution of deferred tasks the timer constructor takes as its argument an object which includes run method and string-valued name field the class must support--( starting threadidentified by nameat given time in the futureand ( canceling threadidentified by name (the cancel request is to be ignored if the thread has already startedhintthere are two aspects--data structure design and concurrency solutionthe two aspects to the design are the data structures and the locking mechanism we use two data structures the first is min-heap in which we insert key-value pairsthe keys are run times and the values are the thread to run at that time dispatch thread runs these threadsit sleeps from call to call and may be woken up if thread is added to or deleted from the pool if woken upit advances or retards its remaining sleep time based on the top of the min-heap on waking upit looks for the thread at the top of the min-heap--if its launch time is the current timethe dispatch thread deletes it from the min-heap and executes it it then sleeps till the launch time for the next thread in the min-heap (because of deletionsit may happen that the dispatch thread wakes up and finds nothing to do the second data structure is hash table with thread ids as keys and entries in the min-heap as values if we need to cancel threadwe go to the min-heap and delete it each time thread is addedwe add it to the min-heapif the insertion is to the top of the min-heapwe interrupt the dispatch thread so that it can adjust its wake up time since the min-heap is shared by the update methods and the dispatch threadwe need to lock it the simplest solution is to have single lock that is used for all read and writes into the min-heap and the hash table