Skip to content

Instantly share code, notes, and snippets.

View aozturk's full-sized avatar

Abdullah Ozturk aozturk

  • London, United Kingdom
View GitHub Profile
final class MyTask implements Runnable {
@Override
public void run() {
System.out.println("My task is started running...");
// ...
throw new ArithmeticException();
// ...
}
}
class MyThreadPoolExecutor extends ThreadPoolExecutor {
public MyThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
@Override
public void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
// If submit() method is called instead of execute()
class MyThreadFactory implements ThreadFactory {
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
private final Thread.UncaughtExceptionHandler handler;
public MyThreadFactory(Thread.UncaughtExceptionHandler handler) {
this.handler = handler;
}
@Override
public Thread newThread(Runnable run) {
final class MyTask implements Runnable {
@Override
public void run() {
try {
System.out.println("My task is started running...");
// ...
anotherMethod();
// ...
} catch (Throwable t) {
System.err.println("Uncaught exception is detected! " + t
namespace AMS {
class IService {
public:
// Create or just return a singleton instance
static IService& instance();
// Destroy the singleton instance
static void destroy();
// Create a messaging domain restricted for communication
// defines a handler class for the message first
class TestMsgHandler : public AMS::IHandler {
public:
virtual void handle(AMS::IMsgObj *baseMsg) {
TestMsg *msg = dynamic_cast<TestMsg *>(baseMsg);
if (msg != 0) {
// process message here
}
}
};
void pub() {
// creates or gets the singleton AMS service
AMS::IService& service = AMS::IService::instance();
// enables exhaustive logging (i.e. message received/sent)
service.debug_mode();
// allows using global logger of AMS service
service.logger().information("publisher side running...");
// either creates a new domain or joins an existing one
class TestMsg : public AMS::IMsgObj {
public:
// give unique id to each message
TestMsg() : IMsgObj(/*msg id*/1) {}
// primitive types and string can be used
std::string name;
double value;
// other class objects can be composed
AdditionalInfo info;
class TwoPartComparator : public rocksdb::Comparator {
public:
// Three-way comparison function:
// if a < b: negative result
// if a > b: positive result
// else: zero result
int Compare(const rocksdb::Slice& a, const rocksdb::Slice& b) const {
int a1, a2, b1, b2;
ParseKey(a, &a1, &a2);
ParseKey(b, &b1, &b2);
rocksdb::Slice key1 = "1";
rocksdb::Slice key2 = "2";
std::string val1 = "one";
std::string val2 = "two";
// populate db first
db->Put(rocksdb::WriteOptions(), key1, val1);
db->Put(rocksdb::WriteOptions(), key2, val2);
rocksdb::ReadOptions readOptions;