我注意到,如果我执行map.getOrDefault("key1",new Object()),即使key1在地图中存在对象,new Object()也会创建.虽然它不是由方法返回但它仍然创建它.例如,
public class Empl {
private int id;
private String name;
public Empl(String name) {
// TODO Auto-generated constructor stub
System.out.println(name);
this.name = name;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return name+id;
}
}
Run Code Online (Sandbox Code Playgroud)
运行以下,
Map<String, Empl> map = new HashMap<String, Empl>();
Empl imp = new Empl("timon");
map.put("1", imp);
System.out.println(map.getOrDefault("1", new Empl("dumnba")));
Run Code Online (Sandbox Code Playgroud)
给出这个输出:
timon
dumnba
timon0
Run Code Online (Sandbox Code Playgroud)
仅当地图中没有默认对象时,才应该创建默认对象吗?如果没有,是什么原因?
我正在尝试与PostgreSQL建立JDBC连接.依赖的驱动程序版本是:9.4-1204-jdbc42和Postgres版本是9.5.0.以下是堆栈:
Caused by: java.lang.UnsupportedClassVersionError: org/postgresql/Driver : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:127)
at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration.dataSource(HibernateConfiguration.java:41)
at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc.CGLIB$dataSource$2(<generated>)
at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc$$FastClassByCGLIB$$17817301.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc.dataSource(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 49 more
Run Code Online (Sandbox Code Playgroud)
请在这里建议问题是什么?
我想用我的用户访问令牌从用户的墙上获取所有公开帖子.我知道这需要read_stream权限.但是,此权限现已弃用.
https://developers.facebook.com/docs/facebook-login/permissions#reference-read_stream
read_stream
此权限仅适用于使用Graph API v2.3或更早版本的应用.
我想使用v2.5版本,那么我现在该怎么办呢?
我有一个具有嵌套节点的JSON对象,可以继续使用任意数量的级别.我需要在点击它的父节点时显示节点的内容.它看起来像这样
"node": [
{
"id": "id of the concept model",
"name": "Curcumin",
"type": "conceptmodel",
"node": [
{
"id": "group1",
"name": "Node 01",
"weight": "70",
"type": "text",
"node": [
{
"id": "group11",
"name": "Node 02",
"weight": "70",
"type": "structure",
"node": []
}
]
}
]
},
{
"id": "id of the concept model",
"name": "Abuse Resistent Technology",
"type": "conceptmodel",
"node": [
{
"id": "group1",
"name": "Category 01",
"weight": "70",
"type": "text",
"node": []
}
]
},
{
"id": "id of the …Run Code Online (Sandbox Code Playgroud) 我有一个在 Kubernetes 集群上运行的 openjdk:8 映像。我添加了内存 HPA(Horizontal Pod Autoscaling),它可以很好地扩展,但由于 JVM 不会将内存从堆释放回操作系统,因此 Pod 不会缩小规模。以下是 hpa.yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: image-server
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: image-server
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 60
Run Code Online (Sandbox Code Playgroud)
解决此问题的一种方法是使用正确的 GC 并使其释放内存,但由于 JVM 出于性能原因设计为不会频繁地从堆中释放内存,因此这样做并不是一个好主意。Kubernetes 有办法处理这个问题吗?就像不检查操作系统的内存使用情况一样,我们是否可以只检查堆和缩放中的内存使用情况?
java ×2
angularjs ×1
facebook ×1
html ×1
javascript ×1
jdbc ×1
jvm ×1
kubernetes ×1
postgresql ×1