Познакомьтесь с пентестом веб-приложений на практике в нашем новом бесплатном курсе
То-то я ни фига понять не могу... вот оно что оказывается.Код на страницах не виден, но он есть, просто движок криво обрабатывает тэги:
ну мне не кажется запуск агентов в тредах вещью надёжнойУ меня все таки примера нет полноценного, но есть вот такой класс.
Суть в том, что мы создаем очередь и кидаем туда задачи, которые созданы от NotesTask.
Сам класс взять отсюда.
Ссылка скрыта от гостейтам же есть набор для обработки коллекции, опять же в потоках
Ссылка скрыта от гостей
Код на страницах не виден, но он есть, просто движок криво обрабатывает тэги:
Посмотреть вложение 61147
public void runNotes() {
while (!isStopped()) {
try {
Runnable runnable = (Runnable) taskQueue.dequeue();
runnable.run();
} catch (InterruptedException ie){
//do nothing, this is just stopping
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void runNotes() {
while (!isStopped()) {
try {
Runnable runnable = (Runnable) taskQueue.dequeue();
runTask(runnable);
} catch (InterruptedException ie){
//do nothing, this is just stopping
} catch (Exception e) {
e.printStackTrace();
}
}
}
private synchronized void runTask(Runnable runnable) {
runnable.run();
}
NotesExecutorService pool = new NotesExecutorService(10);
WorkThread task = new WorkThread();
task.setDocument(document);
pool.execute(task);
pool.shutdown();
package aku.domino.extended.example.misc;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import lotus.domino.NotesThread;
/**
* based on
* http://java.dzone.com/news/java-concurrency-thread-pools
* http://tutorials.jenkov.com/java-concurrency/blocking-queues.html
*
* @author aku
*
*/
public class NotesExecutorService {
private BlockingQueue queue = null;
private List<NotesTask> threads = new ArrayList<NotesTask>();
private boolean isStopped = false;
public NotesExecutorService(int threadsNumber) {
queue = new BlockingQueue(threadsNumber);
startThreads(threadsNumber);
}
private void startThreads(int threadsNumber) {
for (int i = 0; i < threadsNumber; i++) {
threads.add(new NotesTask(queue));
}
for (NotesTask thread : threads) thread.start();
}
public synchronized void execute(Runnable task) throws Exception {
if (this.isStopped) throw new IllegalStateException("ThreadPool is stopped");
this.queue.enqueue(task);
}
public synchronized void shutdown() throws InterruptedException {
this.isStopped = true;
for (NotesTask thread : threads) {
thread.stopThread();
thread.join();
}
}
public class NotesTask extends NotesThread {
private BlockingQueue taskQueue = null;
private boolean isStopped = false;
public NotesTask(BlockingQueue queue) {
taskQueue = queue;
}
@Override
public void runNotes() {
while (!isStopped()) {
try {
Runnable runnable = (Runnable) taskQueue.dequeue();
runnable.run();
} catch (InterruptedException ie){
//do nothing, this is just stopping
} catch (Exception e) {
e.printStackTrace();
}
}
}
public synchronized void stopThread() {
isStopped = true;
this.interrupt(); // break pool thread out of dequeue() call.
}
public synchronized boolean isStopped() {
return isStopped;
}
}
private class BlockingQueue {
@SuppressWarnings("rawtypes")
private List queue = new LinkedList();
private int limit = 10;
public BlockingQueue(int limit) {
this.limit = limit;
}
@SuppressWarnings("unchecked")
public synchronized void enqueue(Object item)throws InterruptedException {
while (this.queue.size() == this.limit) wait();
if (this.queue.size() == 0) notifyAll();
this.queue.add(item);
}
public synchronized Object dequeue() throws InterruptedException {
while (this.queue.size() == 0) wait();
if (this.queue.size() == this.limit) notifyAll();
return this.queue.remove(0);
}
}
}
В 22-м году мы всё ещё продолжаем писать программы на Лотусе.. и это после всего.. нам ли трудностей боятся.ну мне не кажется запуск агентов в тредах вещью надёжной
там и так всё очень зыбко
У меня все таки примера нет полноценного, но есть вот такой класс.
....
доминошные объекты лучше не использовать в таком сценарии, у них с ГЦ всё "странно"У меня так и не взлетело...
Перебираю документы во view, передаю в WorkThread UNID документа, внутри WorkThread заново получаю документ и просто делаю 10 раз System.out.println(document.getUniversalID()). Ломается случайным образом, на любом повторе println. Пропадает документ. Фиксированное количество потоков работает, но с перебором коллекции документов беда.
Обучение наступательной кибербезопасности в игровой форме. Начать игру!