Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.java > #13036

Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem

From Lothar Kimmeringer <news200709@kimmeringer.de>
Newsgroups de.comp.lang.java
Subject Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem
Date 2016-08-24 22:30 +0200
Organization Organization?! Only chaos here!
Message-ID <g3z6z9ebfvwn$.dlg@kimmeringer.de> (permalink)
References <e25pnrFqe4gU1@mid.individual.net>

Show all headers | View raw


Christian H. Kuhn wrote:

> Bislang wurde alle 20 ms die
> Update-Funktion von notifyObservers() aufgerufen:
> 
>     @Override
>     public final void update(final QChessClockSTO _sto) {
>         synchronized (this) {
>             state = _sto.getStatus();
>             (...) // weitere übertragene Daten
>             notified = true;
>             notifyAll();
>         }
>     }
> 
> Im Test wurde eine Aktion auf der zu testenden Klasse aufgerufen, mit
> waitForNotify() auf den eintreffenden update() gewartet und dann die
> entsprechenden asserts vorgenommen. Ob ein update() verpasst wurde oder
> nicht, war nicht wichtig, der nächste kam ja 20 ms später.
> 
>     private void waitForNotify() throws InterruptedException {
>         synchronized (this) {
>             notified = false;
>             while (!notified) {
>                 wait();
>             }
>         }
>     }

Hohl dir den Lock vor dem Aufruf der waitForNotify-Methode. Fuer
detaillierte Analysen wuerde die Nennung der konkreten Klassen
helfen, in denen die Dinge passieren. Ansonsten muesste ich mich
auf die Suche durch deine komplette Sourcebasis machen.


Gruesse, Lothar
-- 
Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Back to de.comp.lang.java | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem "Christian H. Kuhn" <qno-news@qno.de> - 2016-08-24 16:36 +0200
  Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem Lothar Kimmeringer <news200709@kimmeringer.de> - 2016-08-24 22:30 +0200
    Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem "Christian H. Kuhn" <qno-news@qno.de> - 2016-08-26 19:10 +0200
  Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-25 11:03 +0200
    Re: JUnit-Tests funktionieren nur manchmal: Synchronisations-Problem "Christian H. Kuhn" <qno-news@qno.de> - 2016-08-26 20:21 +0200

csiph-web