Tagged Questions
4
votes
1answer
30 views
Synchronized LinkedHashed map
I've written the following code ages ago (10+ years) which is part of a simple chat server.
I'm going to refactor it a bit in java and then for fun I'm going to convert it to Scala
and use Akka actors ...
2
votes
0answers
64 views
Safely network reconnection (netty based)
I am writing a TCP client app using netty
NettyConnectionManager.scala:
...
9
votes
1answer
181 views
Thread-Safe Integer Sequence
I would like to give an Integer to whatever demands it. For that I use the following code
...
7
votes
2answers
116 views
How to make sure all the threads are getting consistent data without performance impacts?
I am working on a project in which I construct a url with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
6
votes
1answer
163 views
Program to shutdown computer after a certain time
I'm trying to make a program that will shutdown my computer after a certain time that I will input via GUI. I'm wondering if I did it the correct way.
Also, will this slow down my computer while it ...
6
votes
1answer
195 views
Is this Android click handler using threads correctly?
I am implementing a thread like the following. Is my implementation correct?
It works well, but I need a check.
...
6
votes
2answers
95 views
My EventBus system followup
This question is a followup from my previous question My EventBus system, and incorporates most points from @rolfl's answer.
It includes, but is not limited to:
Usage of ...
7
votes
1answer
76 views
My EventBus system
I decided to roll out my own EventBus system which is intended to be thread-safe.
Hence a review should focus extra on thread safety apart from all regular concerns.
The ...
12
votes
2answers
208 views
Can I make the thread safe case faster?
The code below is part of one of my projects called largetext, which actually stemmed from a question on StackOverflow.
The goal is to provide access to a very large text file as a ...
4
votes
1answer
84 views
Pre-Java 5 threads
I would like to revise the fundamentals of Java threads on before-Java 5, so that I can understand improvements in Java 5 and beyond.
I started off with a custom collection and need help on:
Things ...
2
votes
1answer
63 views
Decoding big text input: potential concurrency bugs?
The code here will be directly pasted from this project. Quick summary: it is related to a Stack Overflow question.
So, basically, all the code below aims to implement ...
4
votes
1answer
127 views
Correctly implementing the Swing TreeModel
Ideally the Code Review would target the correctness of the approach implementing the Swing TreeModel.
In particular, is the structural separation[1], event message passing, threading[2], object ...
4
votes
2answers
307 views
Using threads to find max in array
I really do not have access to anyone, outside of professors, that is highly knowledgeable about Java so I figured I would post my stuff here to further my knowledge and improve my coding. This is ...
10
votes
2answers
173 views
Thread-safe prime number source
I am working on some multi-threaded code that requires a prime-number source.
The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
4
votes
2answers
93 views
Long Thread & EDT
I’m trying to make a simple gui app that starts a “long” process that can be started and stopped. The process generates random numbers and displays them in a JList. As numbers are being displayed ...
5
votes
3answers
119 views
Feedback on thread safety of the classes
I have following classes. Are they properly guarded for thread safety? Do you see any issues with any of the classes?
...
1
vote
2answers
113 views
Is that correct example of unsafe publication in java? [closed]
There are many examples of unsafe publication on the web. But I cannot find a complete program for reproducing it.
I wrote an example but I do not sure whether it correct or not.
And in case of ...
3
votes
1answer
278 views
How to avoid GSON deserialization if I am aware of error response from the server?
I am working on a project in which I am making a call to one of my servers using RestTemplate which is running a restful service and getting the response back from ...
3
votes
1answer
198 views
How to make builder pattern thread safe in the multithreading environment?
I am working on a project in which I need to have synchronous and asynchronous method of my java client. Some customer will call synchronous and some customer will call asynchronous method of my java ...
8
votes
1answer
141 views
Is this a true Multiton and is it thread safe
See WikiPedia - Multiton Pattern for details on the intent.
Here's the class:
...
5
votes
2answers
836 views
Efficient way of having synchronous and asynchronous behavior in an application
I am working on a project in which I am supposed to make synchronous and asynchronous behavior of my client. In general, how our client will work as below -
Customer will call our client with a ...
2
votes
1answer
242 views
A Spring + GWT + Jetty + Gradle application
I just created a sample project using Spring 3.x, Jetty 9.x, GWT 2.5.1 and Gradle - https://github.com/krishnaraj/JettyGwtSpringSample. Its a slightly modified version of the 'Greeting' gwt ...
2
votes
1answer
580 views
Multithreaded horse race simulation
I'm just starting to get along with threads in Java and I need some code review,
about interfaces, classes, managing threads, correct writing, secure threads, exposed objects etc.
Horse-Race ...
2
votes
1answer
1k views
Thread safe enqueue and dequeue method in Queue
As an exercise, I have implemented a linked queue whose enqueue and dequeue methods are synchronized. There is a ...
1
vote
2answers
159 views
2
votes
3answers
263 views
Java - Unbounded, High-performance(?), Generic, Thread-Safe(?), BatchedCircularQueue
This is my first CodeReview question. I think I'm doing this right...
Anyway, this is a data structure I wrote:
It is an circular first-in-first-out queue (a ringbuffer);
It has batched ...
1
vote
1answer
194 views
Calling different bundles in parallel using ExecutorService
I am working on a project in which I will be having different Bundles. Let's take an example, Suppose I have 5 Bundles and each of those bundles will have a method name ...
3
votes
1answer
201 views
Custom, simple cache with load timeout and expiry; thread safety, tests
The following is a code from one of my projects which implements a loading cache with timeout and expiry. The associated tests are here (mixed with a good number of argument sanity checks tests). I ...
4
votes
1answer
7k 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
116 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 ...
1
vote
1answer
64 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 ...
3
votes
1answer
286 views
Review of simple Java Actor library
How can I improve this code?
Also available from git://github.com/edescourtis/actor.git .
Actor.java
...
3
votes
2answers
120 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
415 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
649 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 ...
3
votes
2answers
932 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
186 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
1k 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 ...
5
votes
2answers
250 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
141 views
1
vote
1answer
99 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
556 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
549 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 ...
3
votes
1answer
805 views
2
votes
2answers
322 views
4
votes
1answer
543 views
Is this proper usage of “safe publication”?
With regards to Safe Publication, consider this piece of code:
...
4
votes
1answer
2k 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 ...
1
vote
1answer
2k 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.
...
3
votes
2answers
672 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 ...
26
votes
5answers
5k 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 ...