wait

java: wait(), notify() and synchronized blocks

拥有回忆 提交于 2019-11-30 13:28:30
I learned that calling an Object's wait() method will release the object monitor, if present. But I have some questions regarding calling notify() on this object by another thread: (when) will the waiting thread wake up, if another (a 3rd) thread owns the object monitor in the meanwhile? will the waiting thread wake up, if a 3rd thread called wait() on this object? is it possible to determine if a thread is waiting for notifying a particular object (java 1.4/java 5) What's happening if wait() will be called in the finalize() method? notify will wake one thread waiting on the monitor. Unless

Pause execution of a method without locking GUI. C#

≡放荡痞女 提交于 2019-11-30 13:27:57
问题 I'm working on a card game in C# for a project on my Intro to OOP paper and have got the game working now but am adding "flair" to the GUI. Currently cards are dealt and appear on the UI instantaneously. I want to have to program pause for a moment after dealing a card before it deals the next. When a game is started the following code runs to populate the PictureBoxes that represent them (will be a loop eventually): cardImage1.Image = playDeck.deal().show(); cardImage2.Image = playDeck.deal(

Wait inside method until event is captured

情到浓时终转凉″ 提交于 2019-11-30 12:49:39
I have this issue with a method in C#. I made a method that calls a function from a dll its called Phone.GetLampMode(); Now Phone.GetLampMode doesnt return anything. The data gets returned in a event the ' onGetLampModeResponse ' event. Is there a way i can wait in my method until i get the data from the onGetLampModeResponse event? public bool checkLamp(int iLamp) { Phone.ButtonIDConstants btn = new Phone.ButtonIDConstants(); btn = Phone.ButtonIDConstants.BUTTON_1; btn += iLamp; Phone.GetLampMode(btn, null); return true; } private void Phone_OnGetLampModeResponse(object sender, Phone

Why do all Java Objects have wait() and notify() and does this cause a performance hit?

做~自己de王妃 提交于 2019-11-30 11:28:17
问题 Every Java Object has the methods wait() and notify() (and additional variants). I have never used these and I suspect many others haven't. Why are these so fundamental that every object has to have them and is there a performance hit in having them (presumably some state is stored in them)? EDIT to emphasize the question. If I have a List<Double> with 100,000 elements then every Double has these methods as it is extended from Object . But it seems unlikely that all of these have to know

Java: Are all monitors released when thread waits on an object?

a 夏天 提交于 2019-11-30 11:11:00
Before a thread can wait on an object, it has to acquire a monitor on that object. The monitor is then released, and the thread attempts to re-acquired it once it awakes. But what happens to other monitors the thread holds when it calls wait ? Consider this example: Object a = // ... Object b = // ... synchronized(a) { synchronized(b) { b.wait(); // continue } } When the thread calls b.wait() , will it release the locks on both a and b , or only b ? Only b . The authoritarian source for these type of questions is the Java Language Specification. The relevant section in this case is 17.8 Wait

Why Lock condition await must hold the lock

为君一笑 提交于 2019-11-30 11:08:27
I am in doubt with that , in Java language, we need to acquire the lock, before we await some condition to be satisfied. For example, int java monitor lock: synchronized(lock){ System.out.println("before lock ..."); lock.wait(); System.out.println("after lock ..."); } or the concurrency utils: Lock lock = new ReentrantLock(); Condition cond = lock.newCondition(); lock.lock(); try{ System.out.println("before condition ..."); cond.await(); System.out.println("after condition ..."); }catch(Exception e){ e.printStackTrace(); }finally{ lock.unlock(); } So, why we can't await, without hold the lock

Protractor : wait for element to become invisible/hidden

此生再无相见时 提交于 2019-11-30 11:02:55
I saw other protractor related post mentioning about how to wait for an element to become visible. However, recently, I ran into an opposite use case. I wanted to wait for an element until it becomes invisible. Since I could not find anything specific about it. I went ahead and came up with a solution. var ptor = protractor.getInstance(); ptor.wait(function() { return element(by.css('#my-css-here')).isDisplayed().then(function(isVisible){ console.log('is visible :' + isVisible); return !isVisible; }); }, 12000).then(function(){ //do whatever you want }); hopefully it helps. any suggestion is

How does implicit wait of Protractor interact with explicit wait?

穿精又带淫゛_ 提交于 2019-11-30 09:40:04
The misunderstanding happens when implicit wait is less than explicit: var timeOut = 5000; var search = element(by.xpath(`//*[@name='qwer']`)); browser.manage().timeouts().implicitlyWait(4000); browser.ignoreSynchronization = true; describe('Protractor Test', function () { beforeEach(function () { browser.get('https://www.google.com.ua'); }); it('EC', function () { console.log('START'); // browser.sleep(timeOut); browser.wait(protractor.ExpectedConditions.presenceOf(search), timeOut); }); }); Overall time: 8.613 seconds. Set implicitlyWait a second lower: 3000 and result is 6.865 seconds. How

Wait for a user event [duplicate]

北慕城南 提交于 2019-11-30 09:21:07
问题 This question already has answers here : How do I return the response from an asynchronous call? (36 answers) Closed last year . I'm developing a javascript class (with jQuery) to create custom popup, but I can not figure out how to "pause" the script to wait for user response (click on the OK button or cancel) the class is like this: function Popup() { } Popup.Show = function(text) { var _response; /* code to draw the popup elements*/ $("#button-ok").on("click",function() { _response = "ok!"

Sleep routine for HTA scripts

人盡茶涼 提交于 2019-11-30 09:07:00
问题 In several of my .HTA scripts that I created, I had the need for the VBScript WScript.Sleep command which simply waits for a number of milliseconds without utilizing the CPU. And when I browse the web, it appears that I am not the only one looking for this: https://www.google.nl/search?q=hta+sleep (I bet that if you read this, you probably need(ed) this as well) The best solution that I could find appears to be the one which uses the PING command. But especially for a situation were just need