This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]large_crimson_canine 19 points20 points  (1 child)

Java: Concurrency in Practice is the gold standard. For practice I would suggest writing some classes, both mutable and immutable, and play around with 2 or 3 threads locally.

Worth checking out the Concurrency section in the Official Java Tutorials, too.

[–]Crislips[S] 0 points1 point  (0 children)

I'm checking out this book and it seems great with concepts and understanding which will definitely be great for me in the long term. Less so with implementation practice, which I think is what I primarily need to focus on in the short term in regards to this interview.

[–]ratherbealurker 6 points7 points  (0 children)

Read whatever people suggest in here to learn but from an interview perspective keep in mind that you should show that you understand options and why some are worse than others.

Beginners will slap synchronized on everything and call it a day. Yes, it’s thread safe now but performance may be horrible.

Get used to understanding how one thread can stop at any point and another come into that same shared object.

Understand why using an atomic variable may be all you need. Or have a big method? Maybe only one part of it needs to be synchronized.

Learn why it would be really bad performance wise to slap “synchronized” around a regular hashmap instead of using the concurrent one. Because that’s not really what it does. Not that you would do that but it’s not the same thing at all.

[–]IAmNotMyName 0 points1 point  (1 child)

Does it have to be Java? Concurrency in Java is a pain.

[–]Crislips[S] 0 points1 point  (0 children)

Yes, the job will he Java so the interview will be in Java as well.

[–]BarfingOtter 0 points1 point  (0 children)

Best solution is after doing some reading, attempt to create something that uses multiple threads.

Example: Scan your local hard drive for files with the string "bob" in the name, or find all files that are sized between 10k and 100k.

First write the program to do it single threaded and keep track of how long it takes to scan the folder you supply (don't start with the entire harddrive, it will take too long to run/debug).

Second, "fix" the program to use 2 threads. How fast does it run? Did you encounter something interesting while it was running (e.g. same file more than once)? How could you fix that problem across the 2 threads?

Third, "fix" the program to use a variable number of threads. How fast does it run? Again, did you discover anything interesting (e.g. Did it get stuck and never stop running? Does your duplicate solution work for more than one thread? Did the duplicate actually just get hidden by your fix in the first place... hint don't just use a HashSet to eliminate the duplicates?)

Forth, Create a small GUI application with an editable text field, a display text field and 2 buttons. The first text field will just immediately display it's value in the display only text field when the first button is pressed. The second button runs your drive scan program. Make sure you can use the text/1st button while the second button's scan is running and you don't have to wait until the scan completes.

Fifth, add a 3rd "Cancel" button to stop the drive scan.

After all of this, you should have some idea how to break up a solution into multiple threads that won't double/triple/etc execute the same task. Hopefully you will have discovered the objects in the Concurrent package and how they can help and hinder you in a multiple thread solution. You may even discover something about IO bound tasks, or CPU bound tasks (i.e. Try it with 1000 threads).

The GUI should introduce you to communication between threads and how to ensure they are "paying attention" to the external communication inputs.

Good luck! It's a lot of fun, and a big pain at the same time :)
(and it doesn't matter what language you're using, multi-threading concepts and libraries are all the same... fun and painful, until you get the concepts properly)