我有一个预定的执行程序将参数重置为0并唤醒所有活动线程以继续处理。但是,在线程初始运行后,它不会再次执行。
ScheduledExecutorService exec = Executors.newScheduledThreadPool(4);
exec.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
logger.info("Setting hourly limit record count back to 0 to continue processing");
lines = 0;
executor.notifyAll();
Thread.currentThread().interrupt();
return;
}
}, 0, 1, TimeUnit.MINUTES);
在类中定义了另一个执行进一步处理的Executor,并且不确定它是否会影响它:
ExecutorService executor = Executors.newCachedThreadPool();
for (String processList : processFiles) {
String appName = processList.substring(0,processList.indexOf("-"));
String scope = processList.substring(processList.lastIndexOf("-") + 1);
logger.info("Starting execution of thread for app " + appName + " under scope: " + scope);
try {
File processedFile = new File(ConfigurationReader.processedDirectory + appName + "-" + scope + ".csv");
processedFile.createNewFile();
executor.execute(new APIInitialisation(appName,processedFile.length(),scope));
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:2)
来自the documentation for ScheduledExecutorService.scheduleAtFixedRate()
:
如果任务的任何执行遇到异常,则后续执行将被禁止。
所以你的任务中有些东西会引发异常。我猜是executor.notifyAll()
IllegalMonitorStateException
要求type_info
投出#include <typeindex>
#include <functional>
#include <unordered_map>
#include <cassert>
struct nullable_type_index
{
constexpr nullable_type_index() : ptr_(nullptr) {}
constexpr nullable_type_index(std::type_info const& ti) : ptr_(std::addressof(ti)) {}
constexpr operator bool() const
{
return bool(ptr_);
}
// I have avoided implicit conversion, but it could probably work
// without any surprises.
std::type_info const& get_type_info() const {
assert(ptr_);
return *ptr_;
}
constexpr bool operator==(nullable_type_index const& other) const {
return ptr_ && other.ptr_
? *ptr_ == *other.ptr_
: ptr_ == other.ptr_;
}
private:
std::type_info const* ptr_;
};
std::size_t hash_value(const nullable_type_index& nti)
{
return nti ? 0 : nti.get_type_info().hash_code();
}
bool operator==(nullable_type_index const& l, std::type_info const& r)
{
return l == nullable_type_index(r);
}
bool operator==(std::type_info const& l, nullable_type_index const& r)
{
return nullable_type_index(l) == r;
}
namespace std {
template<>
struct hash<nullable_type_index>
{
std::size_t operator()(nullable_type_index const& arg) const {
return hash_value(arg);
}
};
}
int main()
{
std::unordered_map<std::type_index, int> workingMap;
workingMap[typeid(int)] = 1;
workingMap[typeid(char)] = 2;
std::unordered_map<int, nullable_type_index> failingMap;
failingMap[1] = typeid(int);
failingMap[2] = typeid(char);
}
的电话:
如果当前线程不是此对象监视器的所有者。
答案 1 :(得分:0)
您计划的任务很可能最终会被删除ScheduledExecutorService.scheduleAtFixedRate
。摘自[
'attribute' => 'numbern',
'filterInputOptions' => [
'class' => 'form-control',
'autofocus' => true,
'selected' => true,
],
],
docker commit mycontainer_id myuser/myimage:12
如果任务的任何执行遇到异常,则后续 执行被压制。
因为你引发了一个未被捕获的异常,所有进一步的执行都被取消了。