How can the wait() and notify() methods be called on Objects that are not threads?

Locking is about protecting shared data. The lock is on the data structure being protected. The threads are the things accessing the data structure. The locks are on the data structure object in order to keep the threads from accessing the data structure in an unsafe way. Any object can be used as an intrinsic … Read more

How to wait for all tasks in an ThreadPoolExecutor to finish without shutting down the Executor?

If you are interested in knowing when a certain task completes, or a certain batch of tasks, you may use ExecutorService.submit(Runnable). Invoking this method returns a Future object which may be placed into a Collection which your main thread will then iterate over calling Future.get() for each one. This will cause your main thread to … Read more

How can I make a program wait for a variable change in javascript?

Edit 2018: Please look into Object getters and setters and Proxies. Old answer below: a quick and easy solution goes like this: var something=999; var something_cachedValue=something; function doStuff() { if(something===something_cachedValue) {//we want it to match setTimeout(doStuff, 50);//wait 50 millisecnds then recheck return; } something_cachedValue=something; //real action } doStuff();

Java : Does wait() release lock from synchronized block

“Invoking wait inside a synchronized method is a simple way to acquire the intrinsic lock” This sentence is false, it is an error in documentation. Thread acquires the intrinsic lock when it enters a synchronized method. Thread inside the synchronized method is set as the owner of the lock and is in RUNNABLE state. Any … Read more

How to wait till the response comes from the $http request, in angularjs?

You should use promises for async operations where you don’t know when it will be completed. A promise “represents an operation that hasn’t completed yet, but is expected in the future.” (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) An example implementation would be like: myApp.factory(‘myService’, function($http) { var getData = function() { // Angular $http() and then() both return promises themselves … Read more