我有一个疑问,Java代码中未使用的导入和未使用的对象是否会产生任何性能影响?
假设一个对象被初始化并且从未使用过,会发生什么?未使用的进口成本是多少?
我正在尝试使用MessageDigest生成MD5总和.我有以下代码.
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
output = bigInt.toString(16);
Run Code Online (Sandbox Code Playgroud)
这不返回32个字符串,而是返回31个字符的字符串 8611c0b0832bce5a19ceee626a403a7
期望的字符串是 08611c0b0832bce5a19ceee626a403a7
输出中缺少前导0.
我尝试了另一种方法
byte[] md5sum = digest.digest();
output = new String(Hex.encodeHex(md5sum));
Run Code Online (Sandbox Code Playgroud)
输出正如预期的那样.
我检查了doc并且Integer.toString根据它进行了转换
使用Character.forDigit提供的数字到字符映射,如果合适,前缀为减号.
并在Character.forDigit方法
如果0 <= digit <radix,则数字参数有效.
有人可以告诉我两种方法有何不同以及为什么删除前导0?
我想从 XML 元素中删除空节点。此 xml 是从供应商生成的,我无法控制 xml 生成。但是由于 XML 几乎没有空节点,我需要递归地删除这些空节点。
这个 xml 是从 OMElement 得到的,我使用 [XMLUtils][1] Sample XML 从这个对象得到一个 Element
<A>
<B>
<C>
<C1>
<C11>something</C11>
<C12>something</C12>
</C1>
</C>
<D>
<D1>
<D11>
<D111 operation="create">
<Node>something else</Node>
</D11>
</D11>
</D1>
<D2>
<D21>
</D21>
</D2>
</D>
</B>
</A>
Run Code Online (Sandbox Code Playgroud)
由于 D21 是一个空节点,我想删除 D21,而现在 D2 是一个空节点,我想删除 D2,但由于 D 有 D1,我不想删除 D。
同样,我有可能得到
<A>
<B>
<C>
</C>
</B>
</A>
Run Code Online (Sandbox Code Playgroud)
现在因为 C 是空的,我想删除 C,然后是 B,最后是节点 A。我试图在Node 中使用 removeChild() 方法来做到这一点
但到目前为止,我无法递归删除它们。有什么建议可以递归删除它们吗?
我递归地尝试获取节点和节点长度。但是节点长度没有帮助
if(childNode.getChildNodes().getLength() == 0 ){
childNode.getParentNode().removeChild(childNode); …Run Code Online (Sandbox Code Playgroud) 我们有头盔图来部署我们的应用程序.我们将configuration.json文件用于应用程序属性并将其加载到配置映射.但用户通常使用自己的配置文件.
默认的configuration.json文件打包在数据直接下的helm图表中.该文件读作
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
{{ (.Files.Glob .Values.appConfigFile).AsConfig | indent 4}}
Run Code Online (Sandbox Code Playgroud)
在价值观
appConfigFile: data/configuration.json
Run Code Online (Sandbox Code Playgroud)
如果用户直接从存储库安装我们的图表,该配置文件如何被覆盖?做--set appConfigFile=/path/to/custom.jsondoen't填入配置图.
如果图表未对目录进行解压缩,则可以将自定义配置文件添加到图表目录中,并使用--set appConfigFile=customData/custom.json作品提供配置文件
从存储库直接部署图表时,是否可以实现文件覆盖?
我有一个Kubernetes集群正在运行.所有pod都在运行.这是一台带有迷你插孔的Windows机器.
但是helm ls --debug会出现以下错误
helm ls --debug
[debug] Created tunnel using local port: '57209'
[debug] SERVER: "127.0.0.1:57209"
Error: Get http://localhost:8080/api/v1/namespaces/kube-system/configmaps?labelSelector=OWNER%!D(MISSING)TILLER: dial tcp 127.0.0.1:8080: connect: connection refused
Run Code Online (Sandbox Code Playgroud)
群集信息
kubectl.exe cluster-info
Kubernetes master is running at https://135.250.128.98:8443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Run Code Online (Sandbox Code Playgroud)
kubectl服务
kubectl.exe get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h
Run Code Online (Sandbox Code Playgroud)
仪表板可在以下访问 http://135.250.128.98:30000
kube配置:
apiVersion: v1
clusters:
- cluster:
certificate-authority: C:\Users\abc\.minikube\ca.crt
server: https://135.250.128.98:8443
name: minikube
contexts:
- …Run Code Online (Sandbox Code Playgroud) 我有一个在服务器A中运行的应用程序.dev环境在服务器B中.我正在尝试远程调试在服务器A中运行的应用程序.
在服务器A中,我将以下命令添加到服务启动脚本
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4554,server=y,suspend=n
Run Code Online (Sandbox Code Playgroud)
服务在服务器A中运行.
当我尝试启动远程调试配置时,它给出了
Failed to connect to remote VM. Connection refused. Connection refused
Run Code Online (Sandbox Code Playgroud)
端口4554在服务器A中是免费的.
还需要做什么其他配置?
关心Dheeraj Joshi
我们正在使用4.2.x版本的spring,并且正在使用ContextSingletonBeanFactoryLocator加载如下所示的bean
BeanFactoryLocator bfLocator = ContextSingletonBeanFactoryLocator.getInstance("classpath:customBeanRefFactory.xml");
BeanFactoryReference ref = bfLocator.useBeanFactory("sharedApplicationContext");
BeanFactory beanFactory = ref.getFactory();
((AbstractApplicationContext) beanFactory).getBeanFactory().setBeanClassLoader(CustomSpringBeanFactory.class.getClassLoader());
return (ApplicationContext) beanFactory
Run Code Online (Sandbox Code Playgroud)
我们计划升级到Spring 5.0.x,并确定ContextSingletonBeanFactoryLocator和诸如BeanFactoryLocator和BeanFactoryReference之类的类已从Spring 5.0版本中删除。
那么,建议使用哪些替代方法来获取应用程序上下文?
@Configuration
@ImportResource("classpath:ourxml")
public class OurApplicationConfiguration {
}
public class OurAppicationFactoryProvider {
ApplicationContext context;
public ApplicationContext getApplicationContext() {
if (context == null) {
synchronized (this) {
if (context == null) {
context = new AnnotationConfigApplicationContext(OurApplicationConfiguration.class);
}
}
}
return context;
}
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法还是其他替代方法?
我有一个不寻常的问题.我有一个函数,这个函数的操作一次可以由两个线程完成.
static int iCount = 1;
public synchronized void myFunct(){
while(iCount >= 3)
{
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
iCount++;
//Do Stuffs
//After operation decrement count
iCount --;
notifyAll();
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是,我想只允许两个线程做一些操作,其他线程必须等待.
但是这里前两个线程递增计数并执行操作,其他线程进入等待状态但没有得到通知.
我想我忽略了一些东西.
我试图从列表中生成一个简单的JR报告.
我一直在从bean:name获取错误检索字段值
此错误是由于错误的getter方法名称,因为jasper使用反射来从bean中获取字段.但即使在更正了getter方法名称之后.我一直得到这个例外.还有其他问题吗?
我的jrxml文件是
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="simpleReport">
<field name="name" class="java.lang.String"/>
<field name="count" class="java.lang.String"/>
<title>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="180" height="15"/>
<textElement/>
<text><![CDATA[Report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band/>
</pageHeader>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[Event Name]]></text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[Count]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20"> …Run Code Online (Sandbox Code Playgroud) helm install通过pre-install钩子执行时,我正在创建一些秘密。
一切正常。但是,helm delete执行时不会删除创建的机密。这是因为使用pre-install来安装的任何资源都被认为是自我管理的。所以我读到这可以使用post-delete钩子完成。
所以问题是:
如何删除后期删除中的机密?
如果我们删除pre-install钩子,那么删除就可以了。但是,当我们表演时,如何保证在创建Pod之前先创建秘密helm install呢?
我试图使用管道输入流写入数据.但是从线程转储看起来管道输入流上有一个锁.
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
FileInputStream fis = null;
GZIPOutputStream gos = null;
byte[] buffer = new byte[1024];
try {
fis = new FileInputStream(file);
gos = new GZIPOutputStream(pos);
int length;
while ((length = fis.read(buffer, 0, 1024)) != -1)
gos.write(buffer, 0, length);
} catch(Exception e){
print("Could not read the file");
}
finally {
try {
fis.close();
gos.close();
}catch (Exception ie){
printException(ie);
}
}
writeObject(pis);
pos.close();
Run Code Online (Sandbox Code Playgroud)
writeobj方法将简单地从流中读取,但read方法被锁定.线程转储表明管道输入流有一些等待.
main" prio=10 tid=0x08066000 nid=0x48d2 in Object.wait() [0xb7fd2000..0xb7fd31e8]
java.lang.Thread.State: TIMED_WAITING …Run Code Online (Sandbox Code Playgroud) 我有一个250Mb的文件要读.应用程序是多线程的.如果我允许所有线程读取文件,则会发生内存不足.我内存不足错误.
为了避免它.我想在内存中只有一个String(从流中读取)的副本,我希望所有线程都使用它.
while (true) {
synchronized (buffer) {
num = is.read(buffer);
String str = new String(buffer, 0, num);
}
sendToPC(str);
}
Run Code Online (Sandbox Code Playgroud)
基本上我想在所有线程完成发送时只有一个字符串副本,我想读第二个字符串,依此类推.
我手上有问题.
我有一个URL,当我启动连接到这个URL并执行url.getContent()时.响应属于类型sun.net.www.protocol.http.HttpURLConnection$HttpInputStream
我试着将输出分配给HttpURLConnectionHttpInputStream h = url.getContent().但我没有成功.我将相应的库导入代码,但仍然没有运气.
如果我在eclipse中检查url.getContent(),它还会在其中显示变量thei $ 0.
我只需要这个$ 0的URL.但到现在为止,我无法撤回它.

在$ 0中有一个变量名称url,我正在尝试获取它.
我也很难理解这个$ 0和锄头来检索它.
使用流后,我得到一些不可读的输出

关心Dheeraj Joshi
java ×9
kubernetes ×3
biginteger ×1
bytecode ×1
debugging ×1
eclipse ×1
import ×1
memory ×1
packages ×1
spring ×1
spring-bean ×1
stream ×1
tostring ×1
xml ×1
xmlnode ×1