I need to create a class to wrap other classes and methods (3rd party) that are not "thread safe". I actually want to create a single threaded class/method.
This should do it:
public class SomeClass {
public static synchronized void performTask(int val) {
//interesting non-thread safe code...
ThisClass thisclass = new ThisClass();
thisclass.dostuff();
ThatClass thatclass = new ThatClass();
thatclass.dootherstuff();
HisClass hisclass = new HisClass();
hisclass.notsure();
}
1 static class with 1 static method which is synchronized. So if multiple objects are using / calling this class. They will have to wait "in-line". Performance will suffer if heavy load.
public class MyClass {
public void mytask() {
//interesting code
SomeClass.performTask(myval); // will wait if some other code block is in SomeClass.performTask?
}