This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Are there any situations where you need to make your code thread safe if all it's doing is reading a file? This is kind of beyond the scope of the exam. Are there any file systems that won't allow concurrent read-only access to a file?
Thread safety is only an issue when multiple threads concurrently read a single value AND at least one thread modifies this value at some point in time.
Its not 100% that there is no synchronization problems while multiple threads reading from a single file. ConsiderHere there is problem as a single thread can't read the file to the fullest. So when each thread is supplying input to some other process then only a partial data of the file will be available from each thread. This problem can't even be solved with the synchronized block, but it can be made sure that a single thread reads the whole file and other threads have no data to read at the end of first thread's execution. To solve this problem you can have a FileReader object inside the run() method to ensure that each thread has the resource to read the same file.
But this example is an inefficient use of thread.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.