Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.SQLException;
- import java.util.Random;
- public class MainTransaktion {
- public static void main(String[] args) throws SQLException {
- // TODO Auto-generated method stub
- int n = 20;
- Transaktion tx = new Transaktion();
- double[] gewicht = {0.15,0.35,0.5};
- Random rand = new Random();
- int id_a = 0;
- int id_b = 0;
- int id_t = 0;
- int delta = 0;
- for( int i = 0; i < 100; i++) {
- double zahl = Math.random();
- //je nach gewichtung TX wählen
- if(zahl >= 0 && zahl <= gewicht[0]) {
- delta = rand.nextInt(10000) + 1;
- System.out.println(tx.analyze(delta));
- }
- else if(zahl > gewicht[0] && zahl <= (gewicht[0] + gewicht[1]) ) {
- id_a = rand.nextInt(n*100000) + 1;
- System.out.println(tx.kontostand(id_a));
- }
- else if(zahl > (gewicht[0] + gewicht[1])) {
- id_a = rand.nextInt(n*100000) + 1;
- id_b = rand.nextInt(n) + 1;
- id_t = rand.nextInt(n*10) + 1;
- delta = rand.nextInt(10000) + 1;
- System.out.println(tx.einzahlen(id_a, id_t, id_b, delta));
- }
- }
- }
- }
- import java.sql.SQLException;
- import java.util.Random;
- public class MainThreads {
- public static void main(String[] args) throws SQLException, InterruptedException {
- // TODO Auto-generated method stub
- int x = 5;
- ThreadTransaktion[] txs = new ThreadTransaktion[x];
- for( int i = 0; i < txs.length; i++) {
- txs[i] = new ThreadTransaktion();
- }
- System.out.println("Programm gestartet");
- for( int i = 0; i < txs.length; i++) {
- txs[i].start();
- }
- //nach 30 sek in die Messphase gehen
- Thread.sleep(240000);
- Transaktion.messen = true;
- System.out.println("-----------------In die Messphase gehen-----------------------------------------\n\n\n");
- //Für 1 Minute dort bleiben
- Thread.sleep(300000);
- //Zurück in die Ausschwingphase für 30sek
- Transaktion.messen = false;
- System.out.println("------------------Aus der Messphase gehen-----------------------------------------\n\n\n");
- Thread.sleep(60000);
- //Thread nicht mehr laufen lassen
- for( int i = 0; i < txs.length; i++) {
- txs[i].running = false;
- }
- //auf Threads warten bis die fertig sind
- for( int i = 0; i < txs.length; i++) {
- txs[i].join();
- }
- //Durchschnittliche Transaktionen pro sekunde
- double average_tx = Transaktion.tx_counter / 300;
- System.out.println("\n\nTX: " + Transaktion.tx_counter);
- System.out.println("\nav-tx pro sekunden: " + average_tx);
- }
- }
- import java.sql.SQLException;
- public class ThreadTransaktion extends Thread {
- Transaktion tx;
- boolean running = true;
- ThreadTransaktion() throws SQLException{
- tx = new Transaktion();
- }
- public void run() {
- try {
- while(running) {
- tx.doBenchmark();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement