Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Questions on Concurrency, part 1
01-03-2012, 07:10 PM #1
Questions on Concurrency, part 1
So I've been reading on concurrency and have some questions on the way (my guide - though I'm not sure if its the best source):
- Processes vs. Threads: Is the difference basically that a process is the program as a whole while a thread can be a (small) part of a program?
- I am not exactly sure why there is a interrupted() method and a InterruptedException. Why should the interrupted() method even be used? It just seems to me that Java just adds an extra layer of indirection.
- For synchronization (and specifically about the one in that link), how does adding the synchronize keyword even fix the problem? I mean, if Thread A gives back its incremented c and Thread B gives back the decremented c and store it to some other variable, I am not exactly sure how the problem is solved. I mean this may be answering my own question, but is it supposed to be assumed that after one of the threads return an answer, terminate? And if that is the case, why would adding synchronize make a difference?
- I read (from some random PDF) that if you have two Threads start() subsequently, you cannot guarantee that the first thread will occur before the second thread. How would you guarantee it, though?
- In synchronization statements, I am not completely sure whats the point of adding synchronized within the method. What is wrong with leaving it out? Is it because one expects both to mutate separately, but to be obtained together? Why not just have the two non-synchronized?
volatilejust a keyword for variables and is synonymous with synchronized?
- In the deadlock problem, how does synchronize even help the situation? What makes this situation different from starting two threads that change a variable?
- Moreover, where is the "wait"/lock for the other person to bowBack? I would have thought that bow() was blocked, not bowBack.
I'll stop here because I think if I went any further without these questions answered, I will not be able to understand the later lessons.