• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Future<>.get method and interruption  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   Hello everyone

   The following code:



In this variant


  console shows:
0
Thread[pool-1-thread-1,5,main]
InterruptedException 1
1
Thread[pool-1-thread-1,5,main]
0
Thread[pool-1-thread-2,5,main]
1
Thread[pool-1-thread-2,5,main]
value2 is 0

  and in this



    0
Thread[pool-1-thread-1,5,main]
1
Thread[pool-1-thread-1,5,main]
value1 is 0
0
Thread[pool-1-thread-1,5,main]
InterruptedException 2
1
Thread[pool-1-thread-1,5,main]

    I cant understand clearly, how its working.
    It turns out that:
In first case:
1. count1 started for execute in thread1.
2. count2 interrupts the execution of count1.
3. count1 resumed in thread1.
4. count2 executed in thread2.

In second case:
1. count1 started for execute in thread1.
2. count1 executed in thread1.
3. count2 started for execute in thread1. (?).
4. count1 interrupts the execution of count2.
5. count2 resumed in thread1.

   I cant understand:
1. Why in first case two threads have applied, and in second case - one thread.
2. Why in second case count1 interrupted the execution of count2 after count1 terminated computations.  





 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!