score:74
I found it out myself now:
boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().
getInputArguments().toString().indexOf("jdwp") >= 0;
This will check if the Java Debug Wire Protocol agent is used.
score:5
You're solving the wrong problem. Your program doesn't need to know this unless it's dealing with eclipse or jvm internals.
Solution
Use a system property with a default value:
int timeout = Integer.parseInt(
System.getProperty("socket.timeout", "1000"));
socket.setSoTimeout(timeout);
And in the debug launch configuration, just add
-Dsocket.timeout=20000
to the call parameters
(If you don't specify the system property, the default value will be used)
References
- System Properties section in the Sun Java Tutorial
- System.getProperty(prop, def) javadocs
score:13
Make the timeout configurable. The simplest way is to just use a system property and read it with Integer.getInteger
:
private final static int SOCKET_TIMEOUT =
Integer.getInteger("com.yourapp.module.socketTimeout", 1000); // default 1 sec
Then, when starting your app for debugging, just set the property from the command line (or an appropriate config file, depending on the environment your app runs in):
java -Dcom.yourapp.module.socketTimeout=1000000 MainClass
This is good because it does not magically alter the behavior when you fire the app up in a debugger, and you can change the timeout when not debugging (for example, if you need to run it somewhere with a slow connection, some day).
(Of course, if your system already uses a config file, it may be appropriate to add this value as an entry there instead.)
As to whether one second is an appropriate timeout... that depends completely on the app. Sometimes it's better to give a correct answer eventually, other times failing quickly is better than waiting for success.
Source: stackoverflow.com
Related Query
- How to Find out if Eclipse is running in debug mode
- How to find out if "debug mode" is enabled
- How to find out if an installed Eclipse is 32 or 64 bit version?
- How do I turn off "Automatically Switch to Debug Perspective" mode in eclipse?
- How to find out which feature contains a needed plug-in on an Eclipse download site
- How do i find out the JDK version Eclipse is using?
- How to view SQL database in Eclipse Debug mode for android
- How do I get maven managed dependencies copied into war\web-inf\lib so I can run my GWT 2.0 app in debug mode within Eclipse?
- How to find out what class is referenced the most?
- How to debug Java code when it is out of sync?
- How to find out what Eclipse is doing in background?
- Java.lang.verifyerror how do I fix or even find out the root cause?
- How to find out which dependency a class belongs to?
- Eclipse : how to find out the Eclipse Version
- How to find out in Eclipse if certain method is called from another method directly or indirectly?
- How can I find out the value of an Eclipse path variable or string variable ( `${some_var}` )?
- How to set nodejs debug mode don't listen 127.0.0.1
- How to set a variable equal to null in debug mode within eclipse
- How to run an external tool in Eclipse in debug mode
- GDB on eclipse debug mode can't find stdlib/rand.c
- Why can't I remote debug? How could I find out why?
- how could find out the end of text position in textview?
- How do I find out the preference page ID of a preference page in Eclipse?
- How to find out what consumes the KeyPressed event in a Swing application?
- How to adjust size and delay of variable info popup window in debug mode in Eclipse?
- How to profile a java application in debug mode with JProfiler
- How do I find out why Eclipse is stuck in an endless build cycle?
- How to find out why Eclipse Xhtml Editor hangs
- PDE development: How to find out where a plugin from my target platform originates from?
- currently using eclipse, not able to get out of debug mode
More Query from same tag
- Pig Latin Sentence Converter
- Hot Code Replace Failed (eclipse)
- Could not Create "Run Configuration" for a Javascript Project
- eclipse not showing all files in project imported from git
- How to force eclipse to create files with 755 permissions?
- are there other possible ways to use groovy in Eclipse except plugin
- How to run a Python3 file from Java on the mac
- Linking css built in eclipse to jsp and getting results
- Ant build.xml working Eclipse. Not working direct
- problems in debugging java source code 1.8 in eclipse
- Eclipse development woes
- Eclipse CDT – Application wide theme configuration
- MS SQL WITH JAVA
- I cannot change the font size of package explorer in Eclipse
- Installing Maven 3.1.1 on Maverick and working with eclipse-Kepler TLM terminal plugin
- Unable to acquire Oracle environment handle
- Activator.start method never called
- SWTBotShell widget not found exception
- fopen fails while debugging in eclipse cdt
- Drawer ITem names Appearing as 0
- How to create jbpm6 web application in Eclipse?
- Unfortunately IrrHelloWorld has stopped - Android
- Variable evaluation fails in Eclipse when debugging JavaScript using Chrome Dev Tools
- Java program controlled by Console?
- How to create an Android app to control Arduino over Wi-Fi?
- Can't start Glassfish 3.1.2.2 on Eclipse Juno
- J2ME obfuscated app stacktrace
- How to set my log4j.properties to my classpath
- Import openCV always shows error
- Debug Android app with Eclipse on real devices