Advertisement
Guest User

Transaktionen

a guest
Dec 11th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import java.sql.SQLException;
  2. import java.util.Random;
  3.  
  4. public class MainTransaktion {
  5.  
  6. public static void main(String[] args) throws SQLException {
  7. // TODO Auto-generated method stub
  8. int n = 20;
  9.  
  10. Transaktion tx = new Transaktion();
  11.  
  12. double[] gewicht = {0.15,0.35,0.5};
  13. Random rand = new Random();
  14. int id_a = 0;
  15. int id_b = 0;
  16. int id_t = 0;
  17. int delta = 0;
  18. for( int i = 0; i < 100; i++) {
  19. double zahl = Math.random();
  20.  
  21.  
  22. //je nach gewichtung TX wählen
  23. if(zahl >= 0 && zahl <= gewicht[0]) {
  24. delta = rand.nextInt(10000) + 1;
  25. System.out.println(tx.analyze(delta));
  26. }
  27. else if(zahl > gewicht[0] && zahl <= (gewicht[0] + gewicht[1]) ) {
  28. id_a = rand.nextInt(n*100000) + 1;
  29. System.out.println(tx.kontostand(id_a));
  30. }
  31. else if(zahl > (gewicht[0] + gewicht[1])) {
  32. id_a = rand.nextInt(n*100000) + 1;
  33. id_b = rand.nextInt(n) + 1;
  34. id_t = rand.nextInt(n*10) + 1;
  35. delta = rand.nextInt(10000) + 1;
  36.  
  37. System.out.println(tx.einzahlen(id_a, id_t, id_b, delta));
  38. }
  39.  
  40. }
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. import java.sql.SQLException;
  50. import java.util.Random;
  51.  
  52. public class MainThreads {
  53.  
  54. public static void main(String[] args) throws SQLException, InterruptedException {
  55. // TODO Auto-generated method stub
  56. int x = 5;
  57. ThreadTransaktion[] txs = new ThreadTransaktion[x];
  58. for( int i = 0; i < txs.length; i++) {
  59. txs[i] = new ThreadTransaktion();
  60. }
  61.  
  62. System.out.println("Programm gestartet");
  63. for( int i = 0; i < txs.length; i++) {
  64. txs[i].start();
  65. }
  66.  
  67. //nach 30 sek in die Messphase gehen
  68. Thread.sleep(240000);
  69. Transaktion.messen = true;
  70. System.out.println("-----------------In die Messphase gehen-----------------------------------------\n\n\n");
  71. //Für 1 Minute dort bleiben
  72. Thread.sleep(300000);
  73. //Zurück in die Ausschwingphase für 30sek
  74. Transaktion.messen = false;
  75. System.out.println("------------------Aus der Messphase gehen-----------------------------------------\n\n\n");
  76. Thread.sleep(60000);
  77.  
  78. //Thread nicht mehr laufen lassen
  79. for( int i = 0; i < txs.length; i++) {
  80. txs[i].running = false;
  81. }
  82. //auf Threads warten bis die fertig sind
  83. for( int i = 0; i < txs.length; i++) {
  84. txs[i].join();
  85. }
  86.  
  87. //Durchschnittliche Transaktionen pro sekunde
  88. double average_tx = Transaktion.tx_counter / 300;
  89.  
  90.  
  91. System.out.println("\n\nTX: " + Transaktion.tx_counter);
  92. System.out.println("\nav-tx pro sekunden: " + average_tx);
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. import java.sql.SQLException;
  103.  
  104. public class ThreadTransaktion extends Thread {
  105. Transaktion tx;
  106. boolean running = true;
  107. ThreadTransaktion() throws SQLException{
  108. tx = new Transaktion();
  109. }
  110.  
  111. public void run() {
  112. try {
  113. while(running) {
  114. tx.doBenchmark();
  115. }
  116. } catch (SQLException e) {
  117. // TODO Auto-generated catch block
  118. e.printStackTrace();
  119. }
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement