本文整理匯總了Java中com.sun.tools.attach.VirtualMachine.list方法的典型用法代碼示例。如果您正苦於以下問題:Java VirtualMachine.list方法的具體用法?Java VirtualMachine.list怎麽用?Java VirtualMachine.list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.tools.attach.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.list方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getVmDescByServerName
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
/**
* 獲取指定服務名的本地JMX VM 描述對象
* @param serverName
* @return
*/
public static List<VirtualMachineDescriptor> getVmDescByServerName(String serverName){
List<VirtualMachineDescriptor> vmDescList = new ArrayList<>();
if (StringUtils.isEmpty(serverName)){
return vmDescList;
}
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor desc : vms) {
//java -jar 形式啟動的Java應用
if(desc.displayName().matches(".*\\.jar(\\s*-*.*)*") && desc.displayName().contains(serverName)){
vmDescList.add(desc);
}else if(hasContainsServerName(desc.displayName(),serverName)){
vmDescList.add(desc);
}else if (isJSVC(desc.id(),serverName)){
VirtualMachineDescriptor descriptor = new VirtualMachineDescriptor(desc.provider(),desc.id(),serverName);
vmDescList.add(descriptor);
}
}
return vmDescList;
}
示例2: repopulate
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
/**
* Update JVM sub-list.
*/
private final void repopulate() {
removeAll();
for (VirtualMachineDescriptor vm : VirtualMachine.list()) {
add(new ActionMenuItem(vm.displayName(), () -> Attach.attach(vm)));
}
revalidate();
}
示例3: main
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
if (args.length < 2 || args.length > 3) {
System.err.println("Usage: java -cp dir/agent.jar:/.../jvm/java-8-jdk/lib/tools.jar " +
"io.prometheus.jmx.shaded.io.prometheus.jmx.Attach pid [host:]<port>:<yaml configuration file>");
System.exit(1);
}
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
VirtualMachineDescriptor selectedVM = null;
for (VirtualMachineDescriptor vmd : vms) {
if (vmd.id().equals(args[0])) {
selectedVM = vmd;
}
}
if (selectedVM == null) {
System.err.println("No such java process with pid=" + args[0]);
System.exit(-1);
}
VirtualMachine attachedVm = VirtualMachine.attach(selectedVM);
File currentJarFile = new File(Attach.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
attachedVm.loadAgent(currentJarFile.getAbsolutePath(), args[1]);
attachedVm.detach();
}
示例4: isProcessAlive
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
@Override
public boolean isProcessAlive(final int pid) {
for (VirtualMachineDescriptor vm : VirtualMachine.list()) {
if (vm.id().equals(String.valueOf(pid))) {
return true; // found the vm
}
}
return false;
}
示例5: getSingleVMD
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
private static Collection<VirtualMachineDescriptor> getSingleVMD(String pid) {
Collection<VirtualMachineDescriptor> vids = new ArrayList<>();
List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vmds) {
if (check(vmd, null, null)) {
if (pid.equals(vmd.id())) {
vids.add(vmd);
}
}
}
return vids;
}
示例6: getVMDs
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
private static Collection<VirtualMachineDescriptor> getVMDs(Class<?> excludeClass, String partialMatch) {
String excludeCls = getExcludeStringFrom(excludeClass);
Collection<VirtualMachineDescriptor> vids = new ArrayList<>();
List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vmds) {
if (check(vmd, excludeCls, partialMatch)) {
vids.add(vmd);
}
}
return vids;
}
示例7: main
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
if (args.length < 2)
{
logOut("Not enough arguments given. This code requires, in this order:");
logOut("1) The PID of JVM to attach to.");
logOut("1) The absolute location of the agent jar to be attached.");
logOut("3) (optional) Any arguments to be passed to the java agent.");
System.exit(1);
}
String vmPidArg = args[0];
Integer.parseInt(vmPidArg); //Just to make sure it's a number.
logOut("Will attempt to attach to JVM with pid " + vmPidArg);
String agentPathString = args[1];
logOut("Attach will be done using agent jar file: " + agentPathString);
// This may cause a compiler error in eclipse, as it is not a java.* class
// It can be fixed by editing the access rules for the JRE system library
// attach to target VM
//First we wait for the target VM to become available
boolean foundTarget = false;
while (!foundTarget) {
List<VirtualMachineDescriptor> allVMs = VirtualMachine.list();
for (VirtualMachineDescriptor oneVM : allVMs) {
if (oneVM.id().equals(vmPidArg)) {
foundTarget = true;
}
}
if (!foundTarget) {
Thread.sleep(1000);
}
}
//Then we attach to it.
VirtualMachine vm = VirtualMachine.attach(vmPidArg);
// load agent into target VM
try {
if (args.length > 2) {
vm.loadAgent(agentPathString, args[2]);
} else {
vm.loadAgent(agentPathString);
}
} catch (java.io.IOException e) {
//This exception is thrown if the test process terminates before the agent does.
//We don't mind if this happens.
}
// detach
vm.detach();
}