当我开始JConsole它标识我的java进程(本地)但它无法连接到它.
Connection Failed: Retry?
The connection to 17424 did not succeed.
Would you like to try again?
Run Code Online (Sandbox Code Playgroud)
再次选择connect会产生相同的错误(17424是java进程的pid).另一方面 jvisualvm工作得很好.在jvisualvm中,我看到以下细节
PID: 17424
Host: localhost
Main class: Conatainer
JVM: Java HotSpot(TM) 64-Bit Server VM (23.6-b04, mixed mode)
Java: version 1.7.0_11, vendor Oracle Corporation
Java Home: /home/aniket/jdk1.7.0_11/jre
JVM Flags: <none>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这种情况?这是一个错误吗?有工作吗?
获取 Spring Webflow 生成的 FLOW ID 完整列表的最佳方法是什么?
这是我的配置:
<webflow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices"
base-path="/WEB-INF/pageFlows">
<webflow:flow-location-pattern value="/**/*-flow.xml"/>
</webflow:flow-registry>
Run Code Online (Sandbox Code Playgroud)
[更新 1] 我应该澄清我想在 Java 代码中执行此操作,而不是通过检查我的配置。
[更新 2] 答案: requestContext.getActiveFlow().getApplicationContext()
假设我有一个类似的代码
public class HelloWorld {
public static String method1(String[] array){return ""+array.length;}
public static String method2(String... array){return ""+array.length;}
public static void main(String args[]) {
System.out.println(method1(new String[]{"test"})); //allowed
//System.out.println(method1("test")); Not allowed
System.out.println(method2(new String[]{"test"})); //allowed
System.out.println(method2("test")); //allowed
}
}
Run Code Online (Sandbox Code Playgroud)
当我做 javap HelloWorld
C:\Users\athakur\JavaProjectWorkspace\HelloWorld\bin\test>javap HelloWorld
Compiled from "HelloWorld.java"
public class test.HelloWorld extends java.lang.Object{
public test.HelloWorld();
public static java.lang.String method1(java.lang.String[]);
public static java.lang.String method2(java.lang.String[]);
public static void main(java.lang.String[]);
}
Run Code Online (Sandbox Code Playgroud)
因此,根据类文件method1和method2采用相同的数组参数.那为什么他们可以采取的输入差异?
类似method1不能采用简单的String输入,因为var arg可以采用变量String输入和数组?
我试图在perl中创建简单的启动脚本,它将在系统启动时启动各种程序.它如下
my @startupPrograms = qw(google-chrome thunderbird skype pidgin );
my @pagesToBeOpenedInChrome = qw(http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox);
sub runPrograms() {
print("Starting startup Programs... \n");
foreach (@startupPrograms) {
my $command = $_;
print "Starting Program " . $command . "\n";
if($command == "google-chrome") {
foreach (@pagesToBeOpenedInChrome) {
$command = $command . " " . $_;
}
}
`$command &`;
print "Program " . $command . " started \n";
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到的输出是
[aniket@localhost TestCodes]$ ./startUp.pl
***** Welcome to startup program! *****
Starting startup Programs... …Run Code Online (Sandbox Code Playgroud) 我有以下代码
public class HelloWorld {
public void printData (Test t) {
System.out.println("Reached 1");
}
public void printData(NewTest t) {
System.out.println("Reached 2");
}
public static void main(String args[]) {
HelloWorld h = new HelloWorld();
h.printData(null);
}
}
Run Code Online (Sandbox Code Playgroud)
我有两个简单的课程
class Test {
}
class NewTest extends Test {
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是 达到2
为什么第二个功能被选中执行而不是第一个?此外,当我通过使另一个类NewTest2扩展Test和类似的printData()函数尝试相同的代码时,它给了我编译时错误.是否有任何规则选择必须执行哪个功能以及何时执行?
至于我的理解是finalize()和GC是两个不同的方面.GC使用finalize()方法释放对象内存.我们无法说明何时会发生GC(即使我们明确地调用System.gc()).但是我们可以在Object上显式调用finalize().
Will the function be executed immediately(memory freed) or it waits till GC
occurs like System.gc() call?
Run Code Online (Sandbox Code Playgroud)
此外,根据文档,对于任何给定对象,Java虚拟机永远不会多次调用finalize方法.
那么当我们先调用finalize()并在稍后的时间调用GC时会发生什么.
If object memory is not freed on explicit call to object.finalize() then would't
it being called again in the GC process violate the calling only once rule?
Run Code Online (Sandbox Code Playgroud) 我在Java中使用FIFO实现并遇到了这个java.util.Queue接口.Dequeue实现它,而后者又由Linked List实现.
我写了以下代码
public class FIFOTest {
public static void main(String args[]){
Queue<String> myQueue = new LinkedList<String>();
myQueue.add("US");
myQueue.offer("Canada");
for(String element : myQueue){
System.out.println("Element : " + element);
}
}
}
Run Code Online (Sandbox Code Playgroud)
两者似乎也做同样的事情.将数据添加到队列的头部.这两种方法有什么区别?任何特殊情况下哪一种比其他情况更有益?
代码:
我有TriangleSummer类有变量的类
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Run Code Online (Sandbox Code Playgroud)
我的主要功能是
public static void main(String args[]) throws IOException {
int noOfTestCases = Integer.parseInt(reader.readLine());
for(int i=0;i<noOfTestCases;i++){
int noOfEntries = Integer.parseInt(reader.readLine());
System.out.println(computeMaxSum(noOfEntries));
}
}
Run Code Online (Sandbox Code Playgroud)
我computeMaxSum()方法的相关部分是
public static int computeMaxSum(int noOfEntries) throws IOException {
int[][] triangle = new int[noOfEntries][noOfEntries];
for(int j=0;j<noOfEntries;j++){
int k=0;
for(String str : reader.readLine().split(" ")){
triangle[j][k] = Integer.parseInt(str);
k++;
}
}
//further logic nothing to do with I/O
}
Run Code Online (Sandbox Code Playgroud)
最后堆栈跟踪是
Exception in thread "main" java.lang.NumberFormatException: For input …Run Code Online (Sandbox Code Playgroud) 通过 Android 构建失败并出现以下错误 -
Error:(23, 68) error: package com.google.api.client.googleapis.extensions.android.gms.auth does not exist
Error:(60, 20) error: cannot find symbol class GoogleAccountCredential
Error:(79, 19) error: cannot find symbol class GoogleAccountCredential
Error:(218, 22) error: cannot find symbol variable GoogleAccountCredential
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚这个类属于哪个库。包是
com.google.api.client.googleapis.extensions.android.gms.authc.GoogleAccountCredential;
我尝试在构建依赖项中添加所有库。现在看起来像下面 -
dependencies {
compile 'com.google.android.gms:play-services-plus:9.0.2'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-base:9.0.2'
compile 'com.google.android.gms:play-services-identity:9.0.2'
compile 'com.google.api-client:google-api-client:1.23.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1' …Run Code Online (Sandbox Code Playgroud) google-app-engine android google-api-java-client google-play-services build.gradle
整个代码都很复杂,所以我直接说到了这一点.代码如下
SSLContext ctx = SSLContext.getInstance("TLS");
Run Code Online (Sandbox Code Playgroud)
如果你读了getInstance(字符串协议)方法的文档,它说
This method traverses the list of registered security Providers, starting
with the most preferred Provider. A new SSLContext object encapsulating
the SSLContextSpi implementation from the first Provider that supports the
specified protocol is returned.
Note that the list of registered providers may be retrieved via the
Security.getProviders() method.
Run Code Online (Sandbox Code Playgroud)
For me Security.getProviders() method gives following providers

Now I have verified that "TLS" protocol is in com.sun.net.ssl.internal.ssl.Provider (index 2 ) and is always selected. …