我必须动态创建一个类,但我想使用类构造函数传递参数.
目前我的代码看起来像
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)
如何用参数调用构造函数?
在我的工作中,我们正在开展不同的项目,其中大部分都是现在的maven项目.有时,我认为如果Maven Central存储库突然出现故障,会发生什么.
现在,有不同的情况可以下降,包括自然灾害,火灾事件等.
据我所知,英国的公司拥有业务连续性管理证书,这意味着他们有计划在遇到任何灾难时运营业务.
我尝试过在线搜索,但在Maven网站上找不到这些信息.
他们有这种证书吗?保证他们将永远运行他们的服务器吗?
任何答案将不胜感激.
我已经用任务执行器设置了文件轮询器
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常量.
我有以下代码工作
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) 我正在使用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吗?如果是,是否有任何我可以使用的例子?
我有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,我找不到为什么它不工作.这是一个错误还是我遗失了什么?
我在Enterprise Architect中有一个类图.
我的一个类有一些方法,我希望我的方法抛出异常.有什么想法我怎么能这样做?
就像在附加图像中我有接口(HsaInterface),它有两个方法,我想要两个抛出异常.
图像显示类

我有一个员工对象
我无法更新员工对象
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) 我有员工对象
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 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秒.
有人可以帮助为什么会这样吗?
我得到每个类的方法(MethodDeclaration).
现在我想知道方法返回类型是否抽象?
我怎样才能做到这一点 ?
我正在使用代码将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日的星期六.
在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)