001    //package edu.unima.ky.parallel;
002    
003    /** 
004     * Finanz version B.
005     * Multi threaded application generates transactions using
006     * objects from KontoB and displays results.
007     * Uses synchronized Konto which cannot become negative.
008     * @author Heinz Kredel. 
009     */ 
010    public class FinanzB {
011    
012        public static void main(String[] args) {
013            
014            for (int i=0; i < 10; i++) {
015            KontoB a = new KontoB(-10.0);
016            KontoB b = new KontoB(300.0);
017    
018            Thread t1 = new UeberweisungB(a,b,10.0); // a is the accont to get amount from.
019            Thread t2 = new UeberweisungB(a,b,10.0); // b is account to add amount to.
020            Thread t3 = new UeberweisungB(a,b,10.0); // 10.0 is the amount to transfer.
021            Thread t4 = new UeberweisungB(b,a,50.0); 
022    
023            t1.start(); t2.start(); t3.start(); t4.start();
024    
025            System.out.println("Stand a = " + a.zeigeGeld() +
026                               " Stand b = " + b.zeigeGeld() );
027    
028            try {
029                t1.join(); t2.join(); t3.join(); t4.join();
030            } catch(InterruptedException e ) { }
031    
032            System.out.println("Endstand a = " + a.zeigeGeld() +
033                               " Endstand b = " + b.zeigeGeld() );
034            }
035        }
036    
037    }