0
votes
0answers
2 views

Best way to call future.get()

The following is a small part of some code I am working on Which is better/faster/nicer? 1. for (Future<Subscription> future : futures) { try { executorService.submit(new ...
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 ...
3
votes
2answers
62 views

Moving from normal threads to ExecutorService thread pools in java

I had my original threading code which worked well, but since my tasks were shortlived, I decided to use thread pools through ExecutorService. This was my original code public class MyRun implements ...
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. ...
2
votes
1answer
56 views

Java - Is this the correct implementation of a timer/timertask to destroy a process that overruns a defined time limit

I was wondering if this is the correct implementation of a times task to destroy a thread after it overruns a predefined time period: it works by creating a getting the thread from ...
0
votes
1answer
59 views

Java concurrent Map of List

I need concurrent HashMap of List as value with following behavior: count of read/write ops approximately equals support add/remove values in lists thread safe iterations over lists After some ...
4
votes
2answers
156 views

Java HTTP Server and multi-threading optimization

I wrote an http server for the management of scores for users and levels. It can returns the highest score per level. It has a simple login with session-key. What do you think could be improved in ...
1
vote
0answers
33 views

Communication with GARMIN throught WEB (Java Socket Programming Code Review)

I am developing a WEB based GPS system and one of its functionallity is to be able to send messages and routes to GARMIN devices. I have never been using sockets before and for some (obvious) reason ...
3
votes
1answer
110 views

Multi threaded circular buffer

I should write a circular buffer with multithread write and single read ability. Here is my solution: public class RingBuffer<E> extends AbstractList<E> implements RandomAccess { ...
1
vote
1answer
173 views

How to update my Swing JTable dynamically. MVC Pattern

I have created a program using a version of MVC architecture. The purpose of the code is to scrape the h1 titles of a list of webpages and to return the results to a JTable. So far I have the ...
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 ...
0
votes
0answers
60 views

Finding Potential Thread Safety issues and Race conditions in my 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 ...
1
vote
1answer
50 views

Log and Count the exception in a Single method

I am tring to count the number of exceptions happening and log those exceptions as well. So what I did is, I created one method addException in which I am counting all the exceptions. addException ...
1
vote
1answer
82 views

Looping through the ResultSet efficiently and the add the values for columns in List<String>

I am working on a multithreaded project in which each thread will randomly find columns for that table and I will be using those columns in my SELECT sql query and then I will be executing that SELECT ...
3
votes
1answer
103 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
1answer
986 views

Java multithreaded file server and client. Emulate TCP over UDP

This is for homework. My task was similar to my last assignment but this time I had to do it with UDP instead of TCP. This basically means I had to emulate TCP over UDP. Multithreading was an ...
1
vote
2answers
122 views

Does my main class have too much code?

For some reason i have the feeling that i should put all of my thread starts and joins in a for loop just to reduce the amount of code. I dunno if that will hurt readability on this class? Also is it ...
1
vote
2answers
71 views

Correct implementation for background task execution in web application?

I have a simple servlet which merely serves some cached data back to the user. I also have a background thread which runs at fixed intervals to refresh the cached data. Is this a reasonable ...
4
votes
1answer
51 views

Timing single operation to not be repeated for a fixed time

Sometimes "a" service does not respond and so we need to restart it. Usually it's a glitch in the network. We can have like 100 calls at the same time so the service cannot be restarted for 100 ...
2
votes
2answers
94 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
52 views

Of the good usage of rhino

This is a sample class using Rhino (1.7R4). I need it because in the context of JSON Schema, regexes should be ECMA 262. One requirement is that it is thread safe, and it is. But I'm not sure I ...
1
vote
1answer
1k views

Multithreaded Client-Server file downloading application

A multithreaded client server program to download image files. If you want to execute it on your machine you should change the file paths. Since there are four files to download the client makes the ...
2
votes
0answers
54 views

Help making multi-platform and removing redundancies in “Auto-Updater”

I whipped up some code recently, but due to the way I make a process this can only be run on windows.... doesn't work QUITE how I want it to either. I would love to get some advice from a more ...
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 ...
1
vote
0answers
74 views

MixpanelAPI - my first open source project

I would love to hear feedback on my first open source project (a very simple async API for Mixpanel) It implements a REST client for this REST HTTP API Review requested on the following aspects: ...
3
votes
2answers
128 views

Closable BlockingQueue

I am working on legacy code, specifically a sort of BoundedBlockingQueue (mainly used as a pipe between different threads). As it is heavily used in the system and the current implementation features ...
1
vote
2answers
369 views

Multithreading concepts with Producer Consumer

I just wanted to confirm if this example I created would qualify as a good example of a multithreaded producer consumer. I would like any review changes on improving this example. I found that static ...
2
votes
1answer
141 views

Ability to forget the memoized supplier value

Guava has a feature request which is asking to provide the ability to forget memoized value on a given supplier. On top on that I needed another functionality where if during the calculation of ...
3
votes
4answers
572 views

Optimizing a thread safe Java NIO / Serialization / FIFO Queue

I've written a thread safe, persistent FIFO for Serializable items. The reason for reinventing the wheel is that we simply can't afford any third party dependencies in this project and want to keep ...
1
vote
1answer
287 views

I am trying to re-write the ATM problem using collections. This is for personal learning. Can you please provide your comments

The problem statement is Write a CashWithDrawal function from an ATM which based on user specified amount dispenses bank notes. Ensure that the following is taken care of Minimum number of bank notes ...
2
votes
1answer
89 views

Thread pausing/resuming implementation

I saw this question on StackOverflow and realized i didn't know how to solve it either, so i started trying to figure it out, using this answer as base point. Could you please review and comment on ...
3
votes
4answers
165 views

Configurable synchronization approach in Java

I am interested in the community opinion about the following approach for the synchronization. Generally it is based on the idea to have a configurable way to apply locking on some logic parts. Any ...
3
votes
1answer
165 views

“Piping” from a callback to an Iterator

My project has a central concept of a Callback<T> which is defined very simply: public interface Callback<T> { void call(T item) throws Exception; } This is used to enforce correct ...
0
votes
1answer
79 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 ...
2
votes
1answer
340 views

Is this a good implementation of a thread-safe singleton using the observer pattern?

I need a singleton that can safely operate in a multi-thread environment. Threading and concurrency is new to me, so I'm not sure if this implementation holds. Take a look: public class ...
2
votes
2answers
467 views

Robust logging solution to file on disk from multiple threads on serverside code

I have implemented a socket listener that runs on my Linux Ubuntu server accepting connections and then starting up a new thread to listen on those connections (classic socket listener approach). ...
1
vote
1answer
276 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
467 views

ReentrantLock with priorities for waiting threads

I am trying to have a ReentrantLock with another way to determinate which thread will have the lock in the waiting queue. ReentrantLock implementation manages a Fair/Unfair policy, that's not what I ...
2
votes
1answer
161 views

What's the motivation for multi-threading in this code?

Here are two ways for writing this sample code (one using multi-threading, one without using multi-threading) - The original code (friend wrote it) uses multi-threading. I would like to know which ...
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 ...
2
votes
1answer
296 views

why does this programs speed not increase?

This is the program I was given, it searches a large array for a max value: import java.util.Date; import java.util.Random; class FindMax { private static final int N = 256 * 1024 * 1024; ...
9
votes
3answers
770 views

Concurrent programming java

I am creating a simple server that accepts a int and returns twice the value received. Here is my code: public class MyServer{ private static int port = 1234; public static void ...
4
votes
3answers
1k views

Java blocking queue

public class BQueue<T> { private Queue<T> q = new LinkedList<T>(); private int limit; public BQueue(int limit) { this.limit = limit; } public ...
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 ...
3
votes
2answers
138 views

Switching functionality on and off in a Scheduled Thread

To illustrate how to do leader election with Apache Zookeeper I've created an straightforward application and I would like to have to threading part of the application reviewed. I've created a simple ...
6
votes
3answers
5k views

Dining Philosophers problem code review

I've just finished my solution to the Dining Philosopher's Problem, but I am not confident with my code because I am still newbie to the concurrency world. I would appreciate it if you could leave me ...
19
votes
2answers
1k views

Interview screw up after this piece of code

I was screwed up after submitting this piece of work. But I have no feedback to know what "BAD" things inside this block of code. The requirements are like this: Connect to the server on a ...

1 2