小编Kau*_*shi的帖子

并发Hashmap - 失败安全问题

我正在尝试使用故障保护的示例ConcurrentHashMap.

下面是我试过的示例片段..

ConcurrentHashMap<String, String> cMap = new ConcurrentHashMap<String, String>();
cMap.put("1", "Windows Phone");
cMap.put("2", "iPhone");
cMap.put("3", "HTC");

Iterator iterator=cMap.keySet().iterator();

while (iterator.hasNext()) {
    System.out.println(cMap.get(iterator.next()));
    cMap.put("Samsung", "S5");
}
Run Code Online (Sandbox Code Playgroud)

输出是:

Windows Phone
HTC
iPhone
Run Code Online (Sandbox Code Playgroud)

这是我理解的一个故障保护示例.

但是当我尝试下面的例子时,我得到了不同的输出.

ConcurrentHashMap<String, String> cMap = new ConcurrentHashMap<String, String>();
cMap.put("1", "Windows Phone");
cMap.put("2", "iPhone");
cMap.put("3", "HTC");

Iterator iterator=cMap.keySet().iterator();

while (iterator.hasNext()) {
    System.out.println(cMap.get(iterator.next()));
    cMap.put("4", "S5");
}
Run Code Online (Sandbox Code Playgroud)

输出是

Windows Phone
HTC
S5
iPhone
Run Code Online (Sandbox Code Playgroud)

上面两个代码片段之间有什么区别.在第二个代码片段中,我添加了cMap.put("4","S5"); 而这正在增加.但是在fisrt片段中,我添加了cMap.put("三星","S5"); 这没有被添加到ConcurrentHashmap.我是否犯了任何错误或者其他可能是这种不同输出的原因.

提前致谢.

java hashmap concurrenthashmap concurrentmodification

4
推荐指数
1
解决办法
2886
查看次数

问题:java.lang.UnsupportedClassVersionError:org/glassfish/jersey/servlet/ServletContainer

我写了一个RESTful Web服务.下面是我的maven依赖项.

<dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.3.3</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <version>3.0.12.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.1_spec</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>net.jcip</groupId>
        <artifactId>jcip-annotations</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.0.12.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.12.Final</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java rest jersey maven jersey-2.0

2
推荐指数
1
解决办法
1万
查看次数

从REST Webservice调用Servlet之前的过滤器

我编写了一个REST Web服务方法setToken(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("token") String token),HeaderFilter并且SampleServlet.下面是Web服务类`@Path("/ service")公共类Service {

/*@Context 
private ServletContext servletContext; 

@Context
private HttpServletRequest request;

@Context
private HttpServletResponse response;*/


@Path("/val/{token}")   
@GET
@Produces("application/xml")
public String setToken(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("token") String token) throws ServletException, IOException {
    String value=token;
    if(request==null){
        System.out.println("Request null");
    }
    System.out.println("Token: " + value);
    if(request!=null){
        request.setAttribute("param", value);
        Wrapper requestWrapper = new Wrapper(request);
        requestWrapper.addHeader("Authorization", token);
        request.getRequestDispatcher("/secure").include(requestWrapper, response);
    }
    return "<token>"+ "<value>"+value+" token value"+"</value>" + "</token>";
}
Run Code Online (Sandbox Code Playgroud)

}` …

java rest web-services servlets servlet-filters

0
推荐指数
1
解决办法
2347
查看次数