小编Ale*_*lex的帖子

我应该同步静态volatile变量吗?

关于这个问题有几个问题,但大多数都围绕这个问题,因为这不是问题的意图.

如果我班上有静态易失性:

private static volatile MyObj obj = null;
Run Code Online (Sandbox Code Playgroud)

在下面的方法中我做:

public MyObj getMyObj() {
    if (obj == null) {
        obj = new MyObj();// costly initialisation
    }
    return obj;
}
Run Code Online (Sandbox Code Playgroud)

我需要同步以确保只有一个线程写入字段,或者任何写入是否会立即显示给评估obj == null条件的其他线程?

换句话说:volatile是否会让你不得不同步访问静态变量上的写入?

java volatile thread-safety

7
推荐指数
1
解决办法
2497
查看次数

Log4J 2配置监控和按位比较

一位同事从Log4J 2.3代码中指出了以下片段:

/**
  * Called to determine if the configuration has changed.
  */
 @Override
 public void checkConfiguration() {
     final long current = System.currentTimeMillis();
     if (((counter.incrementAndGet() & MASK) == 0) && (current >= nextCheck)) {
         LOCK.lock();
         try {
             nextCheck = current + intervalSeconds;
             if (file.lastModified() > lastModified) {
                 lastModified = file.lastModified();
                 for (final ConfigurationListener listener : listeners) {
                     final Thread thread = new Thread(new ReconfigurationWorker(listener, reconfigurable));
                     thread.setDaemon(true);
                     thread.start();
                 }
             }
         } finally {
             LOCK.unlock();
         }
     }
Run Code Online (Sandbox Code Playgroud)

哪里counter是一个 …

java logging java.util.concurrent log4j2

7
推荐指数
1
解决办法
880
查看次数

在制作共享对象时,不能使用Haskell Stack静态二进制重定位R_X86_64_32与`__TMC_END__'

在我stack.yaml的(尝试)中使用以下内容通过Stack编译静态二进制文件时:

ghc-options:
    "*": -static -optc-static -optl-static -optl-pthread -fPIC
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

usr/bin/ld: /usr/lib/gcc/x86_64-amazon-linux/4.8.3/crtbeginT.o: relocation R_X86_64_32 against `__TMC_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-amazon-linux/4.8.3/crtbeginT.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
Run Code Online (Sandbox Code Playgroud)

我正在使用启用了docker的堆栈和一个自定义的Amazon Linux映像,用于构建与AWS Lambda一起使用的静态二进制文件.

我以前没有静态二进制编译的经验,所以我对这个链接器错误感到有点困惑.有什么想法吗?

这是使用-v的gcc args:

/usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE '-Wl,--hash-size=31' -Wl,--reduce-memory-overheads -Wl,--no-as-needed -Wl,-rpath<snipped LOADS> -lHSghc<SNIPPED LOADS> -lpq -lz -lrt -lutil -ldl -lgmp
Run Code Online (Sandbox Code Playgroud)

gcc haskell ghc haskell-stack

7
推荐指数
1
解决办法
2325
查看次数

Spring <jee:jndi-lookup>标签和`SAXParseException`

以下是我的Spring上下文.xml文件的摘录.

    <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <beans:import
        resource="classpath:com/batch/jobs/data-source-context.xml" />

    <job id="xxxx">
        <step id="loadRecord">
            <tasklet>
                <chunk reader="dtaFileItemReader" writer="dtaGroupWriter"
                    commit-interval="${job.commit.interval}" />
            </tasklet>
        </step>
    </job>              
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc"></jee:jndi-lookup>        

    <beans:bean id="incrementerParent" class="${batch.database.incrementer.class}">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="incrementerName" value="ID" />
    </beans:bean>
Run Code Online (Sandbox Code Playgroud)

我得到一个例外说:

nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jee:jndi-lookup'
Run Code Online (Sandbox Code Playgroud)

java spring

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

Maven Codehaus findbugs插件"onlyAnalyze"选项未按预期工作

不耐烦的更新:它很简单,package.-用于子包扫描,而不是package.*按照下面的martoe的回答!

我似乎无法onlyAnalyze为我的多模块项目工作:无论我设置什么包(或模式),maven-findbugs-plugin都不会评估子包,因为我希望传递packagename.*.

为了证明自己或插件有问题(虽然我总是认为它是前者!),我设置了一个具有以下结构的小型Maven项目:

pom.xml
src/
    main/java/acme/App.java
    main/java/acme/moo/App.java
    main/java/no_detect/App.java
Run Code Online (Sandbox Code Playgroud)

这很简单!

POM具有以下findbugs配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.4.0</version>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals><goal>findbugs</goal><goal>check</goal></goals>
                </execution>
            </executions>
            <configuration>
                <debug>true</debug>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <onlyAnalyze>acme.*</onlyAnalyze>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

每个App.java都有以下代码,有两个明显的违规:

package acme;
import java.io.Serializable;

public class App implements Serializable
{
    private static final class NotSer {
        private String meh = "meh";
    }

    private static final NotSer ns = new NotSer();// Violation: not serializable field

    public static void main( String[] args ) …
Run Code Online (Sandbox Code Playgroud)

java findbugs build mojo maven

6
推荐指数
1
解决办法
1998
查看次数

在构建RPM包时运送*.so和二进制文件

我已经创建了一个python应用程序,我想.so在最终的RPM包中发布一些二进制文件.经过长时间的阅读,我找到了一种方法来添加二进制文件/图像和其他数据文件setup.py.现在,当我使用python setup.py bdist_rpm命令构建RPM时,它抱怨架构依赖:

    Arch dependent binaries in noarch package
error: command 'rpmbuild' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

谷歌搜索后我发现我们可以添加:

#%define _binaries_in_noarch_packages_terminate_build 0
Run Code Online (Sandbox Code Playgroud)

或删除线BuildArch: noarch将在packagename.spec文件中,克服了rpmbuild故障.但是,每次我从build/bdist.linux-i686/rpm/SPECS/packagename.spec命令添加或删除行python setup.py bdist_rpm总是覆盖.spe文件.

有没有办法Arch dependent binaries在rpm中避免和发送*.so和其他二进制文件?

python rpm rpm-spec

6
推荐指数
2
解决办法
5193
查看次数

带弹簧启动的 CXF

我正在尝试让 CXF 和 Sprint Boot 运行良好。我有一个名为 SubscriberApi 的 JAX-WS 服务端点。查看 spring-boot 日志,我看到映射成功:

Mapping servlet: 'CXFServlet' to [/api/*]
Setting the server's publish address to be /SubscriberApi
Run Code Online (Sandbox Code Playgroud)

但是,我似乎无法在点击时获得 WSDL:

http://localhost:8080/api/SubscriberApi?wsdl
Run Code Online (Sandbox Code Playgroud)
Mapping servlet: 'CXFServlet' to [/api/*]
Setting the server's publish address to be /SubscriberApi
Run Code Online (Sandbox Code Playgroud)

cxf jax-ws spring-boot

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

WildFly Swarm Nullpointer @Inject bean

我有一个计划服务,通过REST作为JSON获得它的工作.

本Resource类:

import java.io.IOException;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import de.fszm.scheduler.controller.SchedulerController;
import de.fszm.scheduler.entities.MySchedule;

@Path("/schedule")
public class ScheduleRESTResource {

    @Inject
    SchedulerController scheduleController;

    @POST
    @Path("/job")
    @Consumes(MediaType.APPLICATION_JSON)
    public void schedule(MySchedule schedule) throws IOException {
        scheduleController.buildSchedule(schedule);
    }
}
Run Code Online (Sandbox Code Playgroud)

的ScheduleController:

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

import de.fszm.scheduler.entities.MySchedule;

@Named
@RequestScoped
public class SchedulerController {



    public void buildSchedule(MySchedule schedule) {
        System.out.println("Test");
    }

}
Run Code Online (Sandbox Code Playgroud)

的SchedulerMain:

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.wildfly.swarm.container.Container;
import org.wildfly.swarm.jaxrs.JAXRSArchive;

import de.fszm.scheduler.controller.SchedulerController;
import de.fszm.scheduler.entities.MySchedule;
import de.fszm.scheduler.rest.JaxRSActivator;
import …
Run Code Online (Sandbox Code Playgroud)

java cdi weld wildfly wildfly-swarm

6
推荐指数
1
解决办法
812
查看次数

Python AWS Lambda 301 重定向

我有一个用 Python 编写的 lambda 处理程序,我希望对浏览器执行 301 重定向。我不知道如何配置响应Location头(或状态代码)——除了某些属性之外,文档似乎没有涵盖上下文对象中的任何内容。显然context.succeed适用于 Node JS,但这在 Python 中没有帮助。

返回:

{"Location": "http://google.com/"}
Run Code Online (Sandbox Code Playgroud)

导致 API 网关报告:

Fri Dec 09 16:20:53 UTC 2016 : Execution failed due to configuration error: Malformed Lambda proxy response
Run Code Online (Sandbox Code Playgroud)

在测试控制台中。

那么,在使用 API 网关和“AWS Lambda 代理”集成请求时,如何从 Python Lambda 函数执行 301 重定向?

python amazon-web-services aws-lambda

6
推荐指数
1
解决办法
5157
查看次数

Spring - java.lang.NoSuchMethodError:org.springframework.web.accept.ContentNegotiationManager.getStrategies()Ljava/util/List;?

更新我的pom.xml以使用Springframework版本4.2.3(从4.1.2开始)后,应用程序无法启动

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Invocation of init method failed; nested except
ion is java.lang.NoSuchMethodError: org.springframework.web.accept.ContentNegotiationManager.getStrategies()Ljava/util/List;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
Run Code Online (Sandbox Code Playgroud)

我已经尝试过Maven Clean,重建等,但错误仍然存​​在.

我怀疑旧的JAR被关押在哪里,但在哪里?!

spring spring-mvc maven

5
推荐指数
1
解决办法
7842
查看次数