Thursday, February 18, 2016

Java Debug Tricks



http://insightfullogic.com/2014/Jul/10/java-debuggers-and-timeouts/
ou can then detect whether your code is running inside a debugger and set timeouts to significantly longer periods if this is the case. The trick to doing this is to recognise that a debugger involves running a Java agent, which modifies the command-line arguments of the program that it runs under. You can check whether these command-line arguments contain the right agent matcher. 

        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        String jvmArguments = runtimeMXBean.getInputArguments().toString();
        boolean hasDebuggerAttached = jvmArguments.contains("-agentlib:jdwp");
https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/
How to print out the current project classpath
   public static void main (String args[]) {

        ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
         System.out.println(url.getFile());
        }
   }
http://alvinalexander.com/blog/post/java/print-all-java-system-properties
Properties p = System.getProperties();Enumeration keys = p.keys();StringBuilder sb = new StringBuilder();while (keys.hasMoreElements()) {
    String key = (String)keys.nextElement();    String value = (String)p.get(key);    sb.append(key + ": " + value).append("\n");}
return sb;

http://stackoverflow.com/questions/16239130/java-user-dir-property-what-exactly-does-it-mean
It's the directory where java was run from, where you started the JVM. Does not have to be within the user's home directory. It can be anywhere where the user has permission to run java.
So if you cd into /somedir, then run your program, user.dir will be /somedir.
A different property, user.home, refers to the user directory. As in /Users/myuser or /home/myuseror C:\Users\myuser.
http://liubo.loan/2016/10/22/java%E8%BF%9C%E7%A8%8B%E8%B0%83%E8%AF%95/
ava远程调试的原理是两个VM之间通过debug协议进行通信,然后以达到远程调试的目的。两者之间可以通过socket进行通信。
首先被debug程序的虚拟机在启动时要开启debug模式,启动debug监听程序。jdwp是Java Debug Wire Protocol的缩写


Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts