public class Main {
public static final int WORKERS_COUNT = 3;
private static class Worker implements Runnable {
private final BlockingQueue<Integer> queue;
private final int number;
private Worker(BlockingQueue<Integer> queue, int number) {
this.queue = queue;
this.number = number;
}
@Override public void run() {
try {
Integer i = queue.take();
System.out.println("number: "+number+", i ="+i);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
public static void main(String[] args) {
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
queue.add(1);
queue.add(2);
queue.add(3);
ExecutorService pool = Executors.newFixedThreadPool(WORKERS_COUNT);
for (int i = 0; i < WORKERS_COUNT; i++) {
pool.execute(new Worker(queue, i));
}
pool.shutdown();
}
}
public class Main {
static {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe U = (Unsafe) unsafeField.get(null);
File f = new File("C:\\dev\\tmp\\TestA.class");
FileInputStream input = new FileInputStream(f);
byte[] content = new byte[(int)f.length()];
input.read(content);
input.close();
U.defineClass("com.company.a.TestA", content, 0, content.length, Main.class.getClassLoader(), Main.class.getProtectionDomain());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
ClassLoader loader = Main.class.getClassLoader();
System.out.println(loader.getParent());
System.out.println(new TestA());
}
}
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
Cookie[] cookies = req.getCookies();
for (int i = 0; cookies != null && i < cookies.length; i++) {
if ("MyCookie".equals(cookies[i].getName())) {
resp.addCookie(cookies[i]);
}
}
resp.sendRedirect("/myPage");
}
}
interface Common {
void foo();
void bar();
}
interface ConcreteWithSomething {
void doSomething1();
void doSomething2();
}
interface Concrete1 extends Common, ConcreteWithSomething {}
interface Concrete2 extends ConcreteWithSomething {
void doSomething3();
}
class Concrete2Impl implements Concrete2 {
@Inject private Concrete1 delegate;
public void doSomething1() { delegate.doSomething1(); }
public void doSomething2() { delegate.doSomething2(); }
public void doSomething3() {/*...*/}
}
File file = new File("<your_path_here>");
if (!file.createNewFile) {
System.out.pprintln("The instance is already running");
return;
}