小编Mak*_*kky的帖子

使用Constructor参数动态创建Java类

我必须动态创建一个类,但我想使用类构造函数传递参数.

目前我的代码看起来像

Class<HsaInterface> _tempClass = (Class<HsaInterface>) Class.forName(hsaClass);
        _tempClass.getDeclaredConstructor(String.class);
        HsaInterface hsaAdapter = _tempClass.newInstance();
        hsaAdapter.executeRequestTxn(txnData);
Run Code Online (Sandbox Code Playgroud)

如何用参数调用构造函数?

java class dynamic instantiation

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

如果maven central好起来怎么办?

在我的工作中,我们正在开展不同的项目,其中大部分都是现在的maven项目.有时,我认为如果Maven Central存储库突然出现故障,会发生什么.

现在,有不同的情况可以下降,包括自然灾害,火灾事件等.

据我所知,英国的公司拥有业务连续性管理证书,这意味着他们有计划在遇到任何灾难时运营业务.

我尝试过在线搜索,但在Maven网站上找不到这些信息.

他们有这种证书吗?保证他们将永远运行他们的服务器吗?

任何答案将不胜感激.

business-rules maven

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

TaskExecutor 不工作 Spring Integration

我已经用任务执行器设置了文件轮询器

ExecutorService executorService = Executors.newFixedThreadPool(10);

            LOG.info("Setting up the poller for directory {} ", finalDirectory);
            StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows.from(new CustomFileReadingSource(finalDirectory),
                    c -> c.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS, 5)
                            .taskExecutor(executorService)
                            .maxMessagesPerPoll(10)
                            .advice(new LoggerSourceAdvisor(finalDirectory))
                    ))


                    //move file to processing first processing                    
                    .transform(new FileMoveTransformer("C:/processing", true))
                    .channel("fileRouter")
                    .get();
Run Code Online (Sandbox Code Playgroud)

正如所见,我已将threadpool每次轮询设置为固定的 10 条消息和最多 10 条消息。如果我放了 10 个文件,它仍然会一一处理。这里有什么问题?

* 更新 *

尽管我现在有其他问题,但在加里的回答之后它工作得很好。

我已经像这样设置了我的轮询器

setDirectory(new File(path));
        DefaultDirectoryScanner scanner = new DefaultDirectoryScanner();

        scanner.setFilter(new AcceptAllFileListFilter<>());
        setScanner(scanner);
Run Code Online (Sandbox Code Playgroud)

使用的原因是AcceptAll因为同一个文件可能会再次出现,这就是我先移动文件的原因。但是当我启用线程执行器时,多个线程正在处理同一个文件,我假设是因为AcceptAllFile

如果我更改AcceptOnceFileListFilter它可以工作,但是再次出现的同一个文件将不会再次被拾取!可以做些什么来避免这个问题?

问题/错误

在课堂上AbstractPersistentAcceptOnceFileListFilter我们有这个代码

@Override
    public boolean accept(F file) …
Run Code Online (Sandbox Code Playgroud)

java spring-integration spring-integration-dsl

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

更改静态变量可以使用原始包装,但不能使用原始类型

我有一种情况,我必须改变java常量.

我有以下代码工作

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class Main {
    public static final Integer FLAG = 44;

    static void setFinalStatic(Class<?> clazz, String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        Field modifiers = field.getClass().getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, newValue);
    }

    public static void main(String... args) throws Exception {
        System.out.printf("Everything is %s%n", FLAG);
        setFinalStatic(Main.class, "FLAG", 33);
        System.out.printf("Everything is %s%n", FLAG);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我在上面运行,我得到以下输出:

Everything is 44
Everything is 33
Run Code Online (Sandbox Code Playgroud)

但是,如果我将FLAG变量更改为int即

public static final …
Run Code Online (Sandbox Code Playgroud)

java reflection primitive class

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

Apache AVRO与休息

我正在使用Apache AVRO评估我的Jersey REST服务.我正在使用带有Jersey REST的Springboot.

目前我接受JSON作为输入,使用Jackson对象映射器转换为Java Pojos.

我看过不同的地方,但我找不到任何使用带有泽西终点的Apache AVRO的例子.

我找到了这个包含Apache AVRO插件的Github存储库(https://github.com/FasterXML/jackson-dataformats-binary/).

我仍然找不到任何好的例子,如何整合它.有人用过泽西岛的Apache AVRO吗?如果是,是否有任何我可以使用的例子?

java rest jax-rs avro

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

Java Message Formatter无法正常工作

我有String模板

xxxxxxxx xxxxx-xx: [{0}] xxxxxxx xxxxx xxxxxx xxxxxx [{1}] xxxxxx xxxx xxxxx'x xxxxx xxxxxx xxxx [{2}]
Run Code Online (Sandbox Code Playgroud)

即使我提供的所有三个参数仍然不起作用

public static void main(String[] args) {
    String s = "xxxxxxxx xxxxx-xx: [{0}] xxxxxxx xxxxx xxxxxx xxxxxx [{1}] xxxxxx xxxx xxxxx'x xxxxx xxxxxx xxxx [{2}]";

    System.out.println(MessageFormat.format(s,"1","2","3"));
}
Run Code Online (Sandbox Code Playgroud)

输出是:

xxxxxxxx xxxxx-xx: [1] xxxxxxx xxxxx xxxxxx xxxxxx [2] xxxxxx xxxx xxxxxx xxxxx xxxxxx xxxx [{2}]
Run Code Online (Sandbox Code Playgroud)

看输出,它输出{2}而不是3,我找不到为什么它不工作.这是一个错误还是我遗失了什么?

java messageformat java-8

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

在Sparx Enterprise Architect中为操作添加Exception

我在Enterprise Architect中有一个类图.

我的一个类有一些方法,我希望我的方法抛出异常.有什么想法我怎么能这样做?

就像在附加图像中我有接口(HsaInterface),它有两个方法,我想要两个抛出异常.

图像显示类

在此输入图像描述

uml exception enterprise-architect

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

Java 8列表副本

我有一个员工对象

我无法更新员工对象

public class Employee {

    public Employee(Integer id, Integer age, String gender, String fName, String lName) {
        this.id = id;
        this.age = age;
        this.gender = gender;
        this.firstName = fName;
        this.lastName = lName;
    }

    private Integer id;
    private Integer age;
    private String gender;
    private String firstName;
    private String lastName;
Run Code Online (Sandbox Code Playgroud)

我最初设置一个员工列表,但想创建它的副本,然后对其进行更改.即使我正在创建新列表,它仍在更改原始列表

public class ListTest {

    public static void main(String[] args) {

        List<Employee> employeeList = new ArrayList<>();
        Employee employee = new Employee(1, 1, "MALE", "TEST", "TEST");
        employeeList.add(employee);

        List<Employee> listTwo = new ArrayList<>(); …
Run Code Online (Sandbox Code Playgroud)

java arraylist java-8

4
推荐指数
2
解决办法
9342
查看次数

应用OR谓词Java 8

我有员工对象

public class Employee {

    public Employee(Integer id, Integer age, String gender, String fName, String lName) {
        this.id = id;
        this.age = age;
        this.gender = gender;
        this.firstName = fName;
        this.lastName = lName;
    }

    private Integer id;
    private Integer age;
    private String gender;
    private String firstName;
    private String lastName;
Run Code Online (Sandbox Code Playgroud)

我有两个谓词

public static Predicate<Employee> firstNameLike(final String name) {
        return p -> p.getFirstName().contains(name);
    }


    public static Predicate<Employee> isAdultFemale() {
        return p -> p.getAge() > 18 && p.getGender().equalsIgnoreCase("F");
    }
Run Code Online (Sandbox Code Playgroud)

我正在向员工应用多个过滤器,例如

public class TestEmployeePredicates { …
Run Code Online (Sandbox Code Playgroud)

java predicate filter java-8

3
推荐指数
1
解决办法
103
查看次数

套接字超时在Servlet中不起作用

我有一个Java servlet尝试连接到源(使用请求IP地址).

方法如下:

String ip = request.getRemoteAddr();

private void connect(String ip) throws SocketException, IOException {
        Socket socket = new Socket();
        socket.setSoTimeout(1000);
        socket.connect(new InetSocketAddress(ip, Constant.PORT));
    }
Run Code Online (Sandbox Code Playgroud)

现在,如果它没有连接一秒,它应该抛出异常,但它不会在一秒内抛出异常但需要一段时间,如10-15秒.

有人可以帮助为什么会这样吗?

java sockets timeout servlets

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

方法是抽象的或不抽象的

我得到每个类的方法(MethodDeclaration).

现在我想知道方法返回类型是否抽象?

我怎样才能做到这一点 ?

java methods mirror

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

将Java Date转换为Epoch会产生错误的结果

我正在使用代码将java Date对象转换为epoch:

        String str = "" + date;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss.SSS");
        Date formateDate = df.parse(str);
        long epoch = formateDate.getTime();
        return epoch;
Run Code Online (Sandbox Code Playgroud)

如果我用这个价值2013-04-26 08:34:55.705进行测试,那么就会给出1359189295705实际的龙,Sat, 26 Jan 2013 08:34:55 GMT但实际上是今天的星期五,为什么它会说2013年1月26日的星期六.

java format date converter epoch

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

如何让两个Primefaces面板彼此相邻?

在primefaces中是否有一种方法可以将两个primefaces面板放在一起?面板仅以垂直对齐方式呈现.无法将它们水平对齐,彼此相邻.尝试使用h:panelGrid也.但没有运气.

这是代码片段:

<h:panelGrid>
  <p:row>
  <p:column>
       <p:panel id="panel22" header="New Bill">
         <p:inputText>aaa</p:inputText>
       </p:panel>
  </p:column>
  <p:column>
    <p:panel id="panel222" header="Chart">
        <p:inputText>bbb</p:inputText>
      </p:panel>
  </p:column>
 </p:row>
</h:panelGrid>   
Run Code Online (Sandbox Code Playgroud)

java primefaces

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