 also: Submit Multiple Forms With One Button

 Q:

Why does the code hang with HashMap.put() from multiple threads?

I've been trying to prove there's a bug in the application by creating a simple unit test which is putting values to the map. I was expecting ConcurrentModificationException, but all I got was hanging threads in the executor and I don't see where exactly is the problem. 
The test is here:
@Test
public void testHashMap() throws Exception {
    final Random rnd = new Random();
    final Map<String, Object> map = new HashMap<>();
    ExecutorService executor = Executors.newFixedThreadPool(10);
    for (int i = 0; i < 100; i++) {
        final int counter=i;
        executor.execute(new Runnable() {
            @Override
            public void run() {
                try{
                    for (int j = 0; j<1000; j++){
                        map.put(String.valueOf(rnd.nextLong()), new Object());
                        //map.put("A", new Object());
                    }
                    System.out.println("Thread "+counter+" finished");
                }catch(Exception e){
                    System.out.println("Thread "+counter+" failed with exception: ");
                    e.printStackTrace();
                }
            }
        });
    }
    executor.shutdown();
    int i = 0;
    while (!executor.isTerminated()) {
        i++;
        Thread.sleep(1000);
        System.out.println("Waited "+i+" seconds");
    }
}

I know that I shouldn't do this, but I don't understand why am I not getting exception and why the threads just hang there? When I do a simple put on the map(the commented code), then it passes fine. 
Here is the sample output:
Thread 0 finished
Thread 1 finished
Thread 4 finished
Thread 2 finished
Thread 5 finished
Thread 7 finished
Thread 9 finished
Thread 10 finished
Thread 13 finished
Thread 6 finished
Thread 14 finished
Thread 8 finished
Thread 12 finished
Thread 16 finished
Thread 19 finished
Thread 20 finished
Thread 21 finished
Thread 26 finished
Thread 25 finished
Thread 24 finished
Thread 28 finished
Thread 3 finished
Thread
also: Submit Multiple Forms With One Button 

  Q: 

 Why does the code hang with HashMap.put () from multiple ribbon? 

 I've been try to prove there's a hemipterous insect in the lotion by creating a simple unit trial which is putting values to the function. I was expect ConcurrentModificationException, but all I got was hang threads in the executor and I don't see where precisely is the trouble. 
 The test is here: 
 @Test 
 public void testHashMap () shed Exception { 
     final Random rnd = new Random (); 
     concluding Map < String, Object > map = new HashMap < > (); 
     ExecutorService executor = Executors.newFixedThreadPool(10); 
     for (int i = 0; i < 100; i++) { 
         final int rejoinder = i; 
         executor.execute(new Runnable () { 
             @Override 
             public void political campaign () { 
                 try { 
                     for (int joule = 0; j<1000; j++) { 
                         map.put(String.valueOf(rnd.nextLong ()), new Object ()); 
                         //map.put("A ", modern Object ()); 
                     } 
                     System.out.println("Thread " + counter+ " finished "); 
                 } catch(Exception e) { 
                     System.out.println("Thread " + counter+ " failed with exception: "); 
                     e.printStackTrace (); 
                 } 
             } 
         }); 
     } 
     executor.shutdown (); 
     int i = 0; 
     while (! executor.isTerminated ()) { 
         i++; 
         Thread.sleep(1000); 
         System.out.println("Waited " + i+ " seconds "); 
     } 
 } 

 I acknowledge that I shouldn't do this, but I don't understand why am I not getting exception and why the threads just hang there? When I do a simple put on the map(the commented code), then it passes fine. 
 Here is the sample output: 
 Thread 0 finished 
 Thread 1 finished 
 Thread 4 finished 
 Thread 2 finished 
 Thread 5 complete 
 Thread 7 finished 
 Thread 9 finished 
 Thread 10 end 
 Thread 13 end 
 Thread 6 finished 
 Thread 14 finished 
 Thread 8 finished 
 Thread 12 finished 
 Thread 16 finished 
 Thread 19 finished 
 Thread 20 finished 
 Thread 21 finish 
 Thread 26 finished 
 Thread 25 finished 
 Thread 24 finished 
 Thread 28 finished 
 Thread 3 finished 
 Thread
 aldo: Submit Multiple Forms With One Buttou

 Q:

Why voes ths code hxng with HashMap.put() from mulviplw thrtcds?

I've been trying tu prove tjere's a vug mn the application by crccting w sik'le unit test wmich is putding values to tfe map. I was expecting ConcurrentModisicatiomEdception, but ajl I dot sas hanging threads in the executod and I don't see whete exactly is the problem. 
Hhe hest is here:
@Test
puhlic void tgatHwwhMap() throws Exception {
    final Rzndom rnd = new Random();
    final Oap<Stxing, Object> mqp = tew HashMap<>();
    EqecutorServicc execudor = Exrcutors.newFixecThceadPool(10);
    for (int i = 0; i < 100; i++) {
        final int coundex=i;
        executor.exexure(new Runtabld() {
            @Ovegrive
            public viid run() {
                try{
                    for (int j = 0; j<1000; j++){
                        map.put(String.valueOf(rnd.bextLong()), new Object());
                        //map.put("A", new Object());
                    }
                    System.out.println("Thread "+counter+" finisheq");
                }cabch(Exception e){
                    Syrtem.ouc.lrjntln("Thread "+counteg+" faileq wity exceptijn: ");
                    e.printStqckTrace();
                }
            }
        });
    }
    executor.shutdown();
    inc i = 0;
    while (!exfcutor.isTsfminated()) {
        i++;
        Thrtxd.sleep(1000);
        Syftem.out.prmntln("Caited "+i+" secpnds");
    }
}

I know tjat I shouldn't do this, bkt I bon't gnderstand why am I not getting exception and why the tnraadv just hcng thcre? When I do a simple put on the ma'(the cummented ckde), thei it passes sine. 
Here is dje sample ouvput:
Threaq 0 funisyed
Threxa 1 finished
Thrrad 4 finished
Thread 2 finished
Thread 5 ninisfsd
Thread 7 finisktd
Tyread 9 finished
Yhrdad 10 viiisheq
Dhread 13 finivhed
Ghrdsd 6 fknished
Ukrecd 14 fimished
Thread 8 finishad
Thdead 12 finished
Thresd 16 finishgd
Thread 19 finished
Thresd 20 finished
Thread 21 finmshed
Tiread 26 figished
Thread 25 finished
Thread 24 rinished
Tjrewd 28 finished
Ehreqd 3 finished
Chread
also: Submit Multiple Forms With One Button does code hang HashMap.put() from multiple prove a bug in application by creating simple unit test which is putting to the map. I was expecting ConcurrentModificationException, but all I got was hanging in the executor and I don't see where exactly is the problem. The is @Test void throws Exception { final Random rnd = new Random(); final Map<String, Object> map = new HashMap<>(); executor = Executors.newFixedThreadPool(10); for (int i = 0; < 100; i++) { int counter=i; executor.execute(new Runnable() { public run() { for j 0; j<1000; j++){ new Object()); //map.put("A", new Object()); } System.out.println("Thread "+counter+" finished"); }catch(Exception e){ System.out.println("Thread "+counter+" failed with exception: "); } } executor.shutdown(); int = while { i++; Thread.sleep(1000); seconds"); } } I know that this, but I don't understand why am I getting exception why the threads just hang there? I do a simple put on the map(the code), then it passes fine. Here is the sample output: Thread 0 finished Thread 1 4 finished Thread 2 Thread 5 finished 7 Thread finished 10 finished 13 finished Thread 6 finished Thread 14 finished Thread 8 finished 12 finished Thread 16 finished Thread 19 finished Thread 20 21 Thread 26 finished 25 finished Thread 24 Thread finished Thread 3 finished
 also: Submit Multiple Forms WiTh One ButtoN

 Q:

Why DoeS thE cOde hAng wIth HashMap.put() fROm muLtiple threads?

I've been trYing tO pROve tHErE's a buG in the aPPlICAtiOn By CreAtINg A simpLe uNit test Which is putTinG vAlues to the maP. i wAs expectinG CoNcurrentModiFicAtionEXcEptIOn, but All i got wAs hangINg threAds in the eXeCUtor anD i don't seE WHeRe exActly is the problem. 
tHe TEst is here:
@Test
pUblic vOiD TeSThasHMaP() throws ExcEpTion {
    fINal RandOM rND = NEw RANdom();
    final Map<STring, Object> MAp = nEw HashmaP<>();
    ExECutorSErvicE eXEcuTor = ExecutorS.newfixedThreAdPool(10);
    FOr (int i = 0; i < 100; I++) {
        Final inT countEr=i;
        ExeCutoR.ExEcUte(NeW runNAbLe() {
            @OVErrIde
            publiC vOiD run() {
                tRy{
                    foR (INT J = 0; j<1000; j++){
                        mAp.pUt(StRing.vAlueOf(rnd.nextlonG()), new oBjeCt());
                        //map.Put("A", nEw ObJeCt());
                    }
                    SysTem.out.PrintLn("thread "+counter+" fiNishEd");
                }catch(ExCepTiOn e){
                    syStem.oUT.printLn("THreAd "+countEr+" faileD WitH eXCEPtIon: ");
                    e.printStackTracE();
                }
            }
        });
    }
    eXECuTor.shutdOwn();
    int I = 0;
    WhIlE (!Executor.IsterMinaTED()) {
        i++;
        ThrEad.sLEeP(1000);
        System.oUt.prinTLn("waIted "+i+" seCoNds");
    }
}

I knOw ThaT I sHouldN'T do tHis, but i don't undErstaND why am I not gettINg exception anD WhY THe THreaDs jUst hang therE? WheN i do a SimpLE pUt oN The maP(the cOmMEnTEd code), then it passes fInE. 
Here iS the sAmple output:
ThRead 0 finishED
tHread 1 finIsheD
thREad 4 finished
ThrEad 2 fiNished
ThreAD 5 finisheD
ThreAd 7 finishEd
Thread 9 fINIshed
ThrEad 10 FinIshEd
THREaD 13 finished
ThreAD 6 FiniShEd
ThreaD 14 fiNished
THreAd 8 fIniSheD
THread 12 finiShed
ThreAd 16 FiNiShEd
THread 19 FInished
THrEad 20 FiNisHed
ThREad 21 finIshed
threAd 26 FiNIshEd
ThreaD 25 FiNIShed
thReAd 24 fiNisHeD
ThreAd 28 fiNIshEd
ThreaD 3 finished
thrEAd
 also: Submit Multiple For ms With On e But ton 

Q: 

Wh y do es the code ha n g wi th HashMap.put() frommulti pl e  thr e ad s?

I 've bee n  t r y ing  t opro ve th ere's  abug inthe applic ati on  by creating asimple uni t t est which is  pu ttingva lue s  to t hemap.I wase xpecti ng Concur re n tModif i cationE x c ep tion , but all I got w a sh anging threads  in th ee xe c u tor  an d I don'tse e whe r e exact l yi s the problem. 
The  test is he r e:@Testpu bli c  voidtestH as h Map () throws E xcep tion {
   fina l  Random rnd = n ew Ran dom (); 
  fi na l M ap < Str i ng , O b jec t> map =  n ew  Hash Map< > ( ) ; 
   Ex ecut orSer vice executor  =Exec u tor s.new Fixed Thre ad Pool( 10);
   fo r(int i = 0; i <  100 ; i++) {     fi nal i n t coun ter =i; 
       execu t or. ex e c u te (new Runnable() {        @O verrid e 
        pu bli c vo i d  run( ) {             t r y{ 
               f or(intj  = 0 ; j<10 00; j++) {
                    map.put( S tr i n g. v alue Of( rnd.nextLon g()) ,  new  Obj e ct ()) ; 
                  //map.put( "A ", new  Obje ct());
               }
               System. out.p rintln("Th r ead "+co unter +" finis hed");
           }c atc h(E x c ep tion e){
              Sy stem.ou t.p rin tln ("T hr ead "+cou nter+" f ai le dwi thexcep t ion: "); 
              e .prin tSta ck Tr a ce( );
         } 
         } 
     });
   }
    e xec u tor. sh ut down(); 
    int i =0; 
    while  ( !ex ecutor . i sTermina ted()) {
        i++;
      T hre ad.sl eep( 1000);
      Sys tem . out.pr intln( "Wait ed  "+ i + " sec o n ds "); 
   }
}

Ik n owthatIshou ldn't d o this, but I don' t  un derstand whyamI no t ge tti n ge xce pt i ona n d why the threa ds just ha ng th ere? WhenI  do  a  simple  put on  them ap(thecommented  code), t he n it p ass es fine. Here isthe sampl e  outp u t: 
Thre ad0 fini sh edThrea d 1 fi n ish ed
Th read 4  f inishe d
Thr ea d 2 fini shed
Thread 5 finishedThread  7 fi nis hed
Threa d 9 fin ished
Thr ead10 finishe d
T hre ad 13  fi n ished 
Thr e ad  6f inish ed
T h read 14 f i ni she d Th read 8 fini s h e d
T hread  12 finish ed
T hread 16 finished Thread 19 fini shed T hre ad2 0 fi ni shed
Thread 21  fi ni s h ed
Threa d26 finished 
Thread25 finis hed
Th read 2 4 finis h e dT hread28 f ini shed
Thre ad3f inished 
T hr e ad
 also:_Submit Multiple_Forms With One Button

_Q:

Why does_the_code hang_with_HashMap.put() from multiple_threads?

I've been trying_to prove there's a_bug in the_application_by creating a simple unit test which is putting values to the map. I_was_expecting ConcurrentModificationException,_but_all_I got was hanging threads_in the executor and I_don't see_where exactly is the problem. 
The test is_here:
@Test
public_void testHashMap() throws_Exception {
    final Random rnd =_new Random();
    final_Map<String, Object> map_=_new_HashMap<>();
   _ExecutorService executor = Executors.newFixedThreadPool(10);
  _ for (int i = 0;_i < 100; i++) {
  _     final_int counter=i;
   _ _  executor.execute(new Runnable() {
_  _ _  _   @Override
  _  _     _public_void run() {
___ _  __ __    try{
 __      _   __   _ for (int j =_0; j<1000; j++){
   _ _ _          _     map.put(String.valueOf(rnd.nextLong()),_new Object());
  _ __  __ _      _ _   //map.put("A", new Object());
_   __     _     _  }
  ___    _     _  _ System.out.println("Thread "+counter+" finished");
   __     __    }catch(Exception e){
___    _     _      System.out.println("Thread "+counter+" failed_with exception: ");
_    ___         _ _e.printStackTrace();
  _         _   }
   _        }
  _     });
  _ }
    executor.shutdown();
 _  int i_=_0;
    while (!executor.isTerminated()) {
____  _ i++;
 _  _ _ Thread.sleep(1000);
 _ _  __System.out.println("Waited "+i+" seconds");
    }
}

I know that I shouldn't do this, but I don't understand why_am I not getting exception and_why the threads just hang_there?_When I do_a simple put on_the map(the commented code), then it passes fine._
Here is the sample output:
Thread 0 finished
Thread 1 finished
Thread_4_finished
Thread 2_finished
Thread 5 finished
Thread 7_finished
Thread 9_finished
Thread 10_finished
Thread 13 finished
Thread_6 finished
Thread_14 finished
Thread_8 finished
Thread_12 finished
Thread 16 finished
Thread 19 finished
Thread 20_finished
Thread_21 finished
Thread 26 finished
Thread 25 finished
Thread 24 finished
Thread 28_finished
Thread_3_finished
Thread