"VM 정기 태스크 스레드"WatcherThread는 JVM 모니터링 루틴을 어떻게 호출합니까?
별명 "WatcherThread". 이것은 주기적으로 개의 작업 (예 : 성능 카운터 업데이트)을 수행하는 VM 스레드입니다.
스레드의 link
주기 작업 스케줄링을 참조, 그것은 WatcherThread에 의해 설립되었으며, 싱글 개체입니다.
JVM의 스레드가 자주 사용되는 예를 들어, 메모리 모니터링의 실행 상태, JVM 모니터링이 정기적입니다. 그리고 우리는 종종 GC 케이스에 대해
jstat
이 명령을 수행해야합니다.다음과 같습니다.
jstat -gcutil 234832507
이 명령을 사용하면 콘솔의 JVM에서 PID : GC 23483, 250msec 간격 a 인쇄, 총 7 장 인쇄를 지시합니다.
이 내가 JVM 소스 코드에서 찾을 것입니다 link
를 참조하십시오.
"VM Periodic Task Thread"(WatcherThread)가 시작될 때 "실행"기능을 수행해야한다고 생각합니다. 내가 알아 차리는 유일한 사실은 while 루프에서 돌고 있다는 것입니다. jstat
과 같이 WatcherThread가 JVM 모니터링 루틴을 어떻게 호출합니까? 이 while 루프에서 jstat
의 서브 루틴은 어디에 있습니까? WatcherThread가 성능 카운터 등을 업데이트하는 방법에 대해 궁금합니다.
void WatcherThread::run() {
assert(this == watcher_thread(), "just checking");
this->record_stack_base_and_size();
this->set_native_thread_name(this->name());
this->set_active_handles(JNIHandleBlock::allocate_block());
while (true) {
assert(watcher_thread() == Thread::current(), "thread consistency check");
assert(watcher_thread() == this, "thread consistency check");
// Calculate how long it'll be until the next PeriodicTask work
// should be done, and sleep that amount of time.
int time_waited = sleep(); // return 50
if (is_error_reported()) {
// A fatal error has happened, the error handler(VMError::report_and_die)
// should abort JVM after creating an error log file. However in some
// rare cases, the error handler itself might deadlock. Here we try to
// kill JVM if the fatal error handler fails to abort in 2 minutes.
//
// This code is in WatcherThread because WatcherThread wakes up
// periodically so the fatal error handler doesn't need to do anything;
// also because the WatcherThread is less likely to crash than other
// threads.
for (;;) {
if (!ShowMessageBoxOnError
&& (OnError == NULL || OnError[0] == '\0')
&& Arguments::abort_hook() == NULL) {
os::sleep(this, (jlong)ErrorLogTimeout * 1000, false); // in seconds
fdStream err(defaultStream::output_fd());
err.print_raw_cr("# [ timer expired, abort... ]");
// skip atexit/vm_exit/vm_abort hooks
os::die();
}
// Wake up 5 seconds later, the fatal handler may reset OnError or
// ShowMessageBoxOnError when it is ready to abort.
os::sleep(this, 5 * 1000, false);
}
}
if (_should_terminate) {
// check for termination before posting the next tick
break;
}
PeriodicTask::real_time_tick(time_waited);
}
// Signal that it is terminated
{
MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
_watcher_thread = NULL;
Terminator_lock->notify();
}
}
'jstat'는 명령 행 도구입니다. 나는 JVM이 외부 명령 행 도구를 호출하지 않는다는 것을 확신한다. 이 루프는 각 정규 반복에서'PeriodicTask :: real_time_tick'을 호출합니다. 그 외에도 소스에 대한 참조없이 텍스트 블록을 인용했습니다. 어떤 상황에서 누가 그것을 작성 했습니까? – Holger
@Holger 참조 링크를 추가했습니다. 'PeriodicTask :: real_time_tick'에서 찾을 수있는 것은 타이머에 관한 회계 정보를 제공한다는 것입니다. 가장 눈에 띄는 것은'_tasks [index] -> execute_if_pending (delay_time)'입니다. 'task()'에서 실제 작업을하는 것처럼 보입니다. 알았다! 샘플을 수행하는 경우 마침내'StatSamplerTask :: task'를 호출한다고 생각합니다. – skytree
실행 가능한 정보를 얻기위한 두 번째 소스를 정말로 고려 했습니까? 나는 "Making making making"과 "Making making making"의 차이점과 그 원래 번역문이 깨진 번역문보다 더 의미가 있는지 궁금해하고 있습니다. – Holger