3
votes
1answer
75 views

Dining Philosophers problem Solution with Java Reentrant Lock

I have implemented Dining Philosopher problem using ReentrantLock in java. The goal of this program is Every philosopher should follow the workflow of think,getchopsticks,eat,putchopsticks (No ...
1
vote
1answer
69 views

Thread safe settings

I'd like to design a settings class thread save. The settings have 2 attributes: String x and int y and should provide listener functionality to notify listener about changes. The problem is, how to ...
1
vote
1answer
32 views

Ensuring my program is thread safe

I have a class which is responsible for waiting until a message is added to a message list and then sending it off to get processed withdrawMessages - waits for message. I wait a total of 2 minutes ...
3
votes
1answer
106 views

Review of simple Java Actor library

How can I improve this code? Also available from git://github.com/edescourtis/actor.git . Actor.java package com.benbria.actor; public interface Actor<T> extends Runnable { public ...
3
votes
2answers
56 views

Is this a scenario to use volatile instead of synchronized?

I want to know if using volatile in this scenario will give a better performance than using synchronization. Specifically for the paused and running instance variable in the SimulationManager class. ...
3
votes
1answer
192 views

Java thread safety and caching techniques

This is my first Java multi-threading code. It is part of an Android application that is a client to a webpage that serves books. Each page of the book is in a separate PDF, and the Book class ...
3
votes
1answer
104 views

Thread Safety issues in the multithreading code

I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using ...
2
votes
2answers
96 views

Simple FIFO Job list in Java

For the first time I have to play with Threads in java. Basically, my code is a simple FIFO job queue. The main thread regularly puts jobs in the queue wich need to be executed. The code below is a ...
2
votes
1answer
61 views

BlockingQueue Implemetation using ReentrantLock

I was writing my own implementation of BlockingQueue for practice. I am trying to avoid using the synchronized keyword for the methods. I would instead like to use ReentrantLock. What is the best way ...
1
vote
2answers
333 views

Lock-Free Ring Implementation

I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger. The CircularRing pre-allocates LoggableEntity elements and stores ...
4
votes
2answers
179 views

Multithreading correctly done?

I rarely write multithreaded code, and am on shaky ground when doing so. I make mistakes. I would like a sanity check of something I am going to introduce in one of my apps. There will be exactly ...
3
votes
2answers
117 views

How is this ThreadSafe?

Given the class Sequence: //This method getNext must return a unique value nextValue public class Sequence { @GuardedBy("this") private int nextValue; public synchronized int getNext() { ...
0
votes
1answer
80 views

Thread Safe Server Querier

I wanted to make a class that connects to my server and returns a value, a url in this case. As Android 4.0 doesn't let me run network task on the main UI thread(rightly so) I have made this. Please ...
1
vote
1answer
277 views

Loading an Object from File with Type-Safety and Thread-Safe access

I'm attempting to write a bit of code that allows for easy and safe access to objects in a file. It seems to work great but I was curious if there was an easier way to do this or if Java already has ...
4
votes
1answer
299 views

is this thread safe?

I am using this code for receiving log messages from my clients I receive more than 1000 connections per minute. I want to increase my log handling. I did with java threading. I have a doubt if it ...
1
vote
1answer
364 views

Thread safe cache implementation

Please review this implementation of thread-safe chache. public class StaticCacheImpl<T extends Entity> implements StaticCache<T> { private boolean set = false; private ...
2
votes
2answers
221 views

Is this method thread safe?

Are these methods getNewId() & fetchIdsInReserve() thread safe ? public final class IdManager { private static final int NO_OF_USERIDS_TO_KEEP_IN_RESERVE = 200; private static final ...
3
votes
1answer
258 views

Is this code an example of safe publication or unsafe publication?

Hi all I was wondering in this piece of code: public class Test { public static void main(String args[]) { ThreadB t = new ThreadB(); t.start(); t.Grab(new Bag("HI")); ...
4
votes
1answer
1k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared scheduling functionality. A thread is ...
1
vote
1answer
1k views

Simple multi-threaded Java server loop

I'm new to sockets and servers in general and I would like to know if I'm doing something really wrong in the following server loop for spawning threads to process requests. private static ...
3
votes
2answers
588 views

Thread Safe Service to Perform Tasks in a Queue

In answering a question on SO, I provided this example. The intention was to provide a thread safe service that queues requests to make directories. I figured I could definitely use some review on ...
22
votes
5answers
3k views

Is this (Lock-Free) Queue Implementation Thread-Safe?

I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently. Would you ...