This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Long myNtfSeqNbrCounter = new Long(0); | |
private Long getNotificationSequenceNumber() { | |
Long result = null; | |
synchronized(myNtfSeqNbrCounter) { | |
result = new Long(myNtfSeqNbrCounter.longValue() + 1); | |
// ... | |
myNtfSeqNbrCounter = new Long(result.longValue()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
private Helper helper = null; | |
public Helper getHelper() { | |
if (helper == null) | |
helper = new Helper(); | |
return helper; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
private Helper helper = null; | |
public Helper synchronized getHelper() { | |
if (helper == null) | |
helper = new Helper(); | |
return helper; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
private Helper helper = null; | |
public Helper getHelper() { | |
if (helper == null) { | |
synchronized (this) { | |
if (helper == null) { | |
helper = new Helper(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RequestRunnerExecutor | |
{ | |
private final Set<HttpWebResponse> runningRequests = new HashSet<>(); | |
public ListenableFuture<Boolean> runRequest( URI uri ) | |
{ | |
final Future<HttpWebResponse> futureResponse = httpClient.execute( | |
HttpAsyncMethods.createGet( uri ), | |
new ByteConsumer(), | |
new ResponseCallback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////// There's an infitite loop hidden in this code //////////////////////////// | |
class Foo | |
{ | |
private final HashMap<String, Integer> scores = new HashMap<>(); | |
synchronized resetCount( String name ) | |
{ | |
scores.put( name, 0 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* When a Task is aborted, it should b aborted in the taskQueue and its state should be | |
* persisted to taskStorage. There is also a start method with similar requirements. | |
* | |
* Below are different implementation alternatives for a REST method. | |
*/ | |
// Alt. 1 -- Task knows about taskStorage and taskQueue: | |
taskStorage.getTask( id ).abort().save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestRunResource | |
{ | |
private final TestQueue testQueue; | |
private final TestStorage testStorage; | |
public void stopTestRun( @Auth User user, @PathParam( "id" ) String testId ) | |
{ | |
TestRun test = getTestRun( user, testId ); // gets testrun from testStorage | |
testQueue.abort( test ); | |
test.abort(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.smartbear.saas.rs.storage; | |
import com.github.fakemongo.Fongo; | |
import com.mongodb.util.JSONSerializers; | |
import org.jongo.Jongo; | |
import org.jongo.MongoCollection; | |
import org.junit.Test; | |
import static java.util.stream.Collectors.joining; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.smartbear.saas.rs.model; | |
import com.google.common.collect.ImmutableSet; | |
import org.junit.Test; | |
import java.util.Set; | |
import static org.hamcrest.Matchers.equalTo; | |
import static org.hamcrest.Matchers.is; | |
import static org.junit.Assert.*; |