我正在尝试使用Spring 3 @ImportResource注释找到导入多个spring xml上下文文件的语法.
我尝试使用逗号分隔文件名,如下图所示,但这不起作用:
@Configuration
@ImportResource("spring-context1.xml", "spring-context2.xml")
public class ConfigClass { }
Run Code Online (Sandbox Code Playgroud)
@ImportResource的文档说"表示包含要导入的bean定义的一个或多个资源".所以我认为应该有一种方法来指定多个上下文文件.令人惊讶的是,我无法在Google上找到任何示例
请帮我在下面的代码中找到Thread泄漏的原因.该TestThread甚至运行后收集的数据不被垃圾()已完成(从安慰print语句验证)和主要方法已退出(从print语句和Profiler工具验证).
的TestThread,但是,如果得到它被设置为守护线程即垃圾收集t.setDaemon(true).下面的代码只是一个示例代码,用于说明我的应用程序中的问题.我正在尝试使用一些预先存在的调度类(由其他人使用设计ScheduledExecutorService).我注意到,当我继续Runnable使用类调度多个s时,创建的线程永远不会被垃圾收集.
public class ThreadTest {
static void runThreadWithExecutor() {
final String name = "TestThread";
ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(
new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, name);
t.setDaemon(false);
return t;
}
});
ses.schedule(new Runnable() {
@Override
public void run() {
System.out.println("entered " + name);
System.out.println("exiting " + name);
}},
2,
TimeUnit.SECONDS);
}
public static void main(String[] args) throws InterruptedException {
System.out.println("entered main");
runThreadWithExecutor(); …Run Code Online (Sandbox Code Playgroud) 我已经删除了代码以重现抛出错误的示例:
public class Test {
public static void main(String[] args) {
NavigableSet<String> set = new TreeSet<String>(
Arrays.asList("a", "b", "c", "d"));
NavigableSet<String> set2 = new TreeSet<String>();
set2 = set.tailSet("c", false);
set2.addAll(set.headSet("b", true));
System.out.println(set2);
}
}
Run Code Online (Sandbox Code Playgroud)
代码的目的是在检索集合的子集时实现某种翻转.例如,在上面的例子中,我想要c [exclusive]到b [包含]的所有元素.我注意到如果我注释掉tailSet()或headSet()行,其余的代码效果很好.但是,当我有两条线时,我明白了
java.lang.IllegalArgumentException:键超出范围
在我的代码中,我有两种测试类型:快速单元测试和慢速性能测试。我试图确保性能测试永远不会运行,除非用户明确希望运行它们(例如,使用正确的测试套件或maven构建配置文件),因为这会导致网格上计算量很大的远程进程的启动。
我了解如何使用maven-surefire-plugin创建排除(或包括)特定测试的构建配置文件,如本网站所述。但是,我的问题是,我还没有找到一种将测试从默认运行中排除的方法,同时仍然提供了在需要时运行测试的选项。默认运行是指:
在以上两种情况下,它都会运行所有单元测试(包括我希望默认排除的慢速测试)。如果我尝试运行的构建配置文件中有错字,也会发生同样的事情。
有没有办法可以将性能测试从默认运行中排除,而不必将其移动到单独的Maven模块中?
public ScheduledFuture<?> executeTaskWithDelay(String name,
final Runnable runnable, Period delay, boolean isDaemon) {
ScheduledExecutorService executorService =
Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory(
name, isDaemon));
ScheduledFuture<?> future = executorService.schedule(runnable,
delay.toStandardDuration().getMillis(), TimeUnit.MILLISECONDS);
executorService.shutdown();
return future;
}
Run Code Online (Sandbox Code Playgroud)
当我分析应用程序时,我注意到这个方法创建的调度线程在执行之前总是处于"正在运行"而不是"等待"状态.如果我删除executorService.shutdown()它会做我想要的(即线程保持等待状态,直到它们运行的时间).但是,如果没有executorService.shutdown(),nonDaemon线程在执行后永远不会被垃圾收集.有没有办法可以确保线程在执行前始终处于等待状态?或者我可以使用其他替代方法来确保:
以下是第9项中的示例代码:
public final class PhoneNumber {
private final short areaCode;
private final short prefix;
private final short lineNumber;
@Override
public int hashCode() {
int result = 17;
result = 31 * result + areaCode;
result = 31 * result + prefix;
result = 31 * result + lineNumber;
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
Pg 48指出:"选择值31是因为它是一个奇数素数.如果它是偶数且乘法溢出,信息就会丢失,因为2的muiltiplication相当于移位."
我理解乘2的概念相当于位移.我也知道当我们将一个大数乘以一个大的奇素数时,我们仍会得到溢出(因此信息丢失).我没有得到的是为什么由大奇数素数乘法引起的信息丢失优于由大偶数乘法引起的信息丢失.
我正在测试我在Apache Web服务器上运行的Python Flask Web应用程序的限制,通过发出一个超过30分钟的请求来完成.该请求需要数千个数据库请求(一个接一个)到MySQL数据库.我理解这应该理想地在apache服务器之外作为一个单独的异步进程运行,但是现在让我们忽略它.我遇到的问题是,虽然当我在我的Mac上测试它时完全运行,但它在Linux服务器(AWS EC2上的Amazon linux)上运行时会突然死亡.我无法确切地知道是什么杀了它.我检查过服务器内存不足.该过程使用非常少的RAM.我无法找到任何Apache配置参数或任何对我有意义的错误消息(即使在将apache logLevel设置为debug之后).请到哪里查看我需要帮助.以下是有关我的设置的详细信息:
运行
服务器:分别在8分钟,27分钟,21分钟和22分钟后死亡.请注意,大多数这些运行的是一个UAT服务器上,这是服务器正在处理的唯一请求.
Mac:它在服务器上运行得慢得多.该过程成功运行,耗时2小时47分钟.
Linux Server详细信息:
2个虚拟CPU和4GB RAM
OS(输出uname -a)
Linux的IP-172-31-63-211 3.14.44-32.39.amzn1.x86_64#1 SMP星期四06月11 20点33分38秒UTC 2015 x86_64的x86_64的x86_64的GNU/Linux的
Apache error_log: https ://drive.google.com/file/d/0B3XXZfJyzJYsNkFDU3hJekRRUlU/view ? usp = sharing
Apache配置文件: https ://drive.google.com/file/d/0B3XXZfJyzJYsM2lhSmxfVVRNNjQ/view?usp=sharing
Apache版本(输出apachectl -V)
Server version: Apache/2.4.23 (Amazon)
Server built: Jul 29 2016 21:42:17
Server's Module Magic Number: 20120211:61
Server loaded: APR 1.5.1, APR-UTIL 1.4.1
Compiled using: APR 1.5.1, APR-UTIL 1.4.1
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes …Run Code Online (Sandbox Code Playgroud) 当我根据示例在Button中添加Text元素时,文本以大写形式显示.我需要显示一个小写文本的按钮.我使用的是原生基础版本2.1.4.任何有关这方面的帮助将非常感激.例如,如果我包含下面的代码,按钮会说SUBMIT而不是Submit:
import { Button} from 'native-base';
<Button>
<Text>Submit</Text>
</Button>
Run Code Online (Sandbox Code Playgroud) I tried to run this hello world app on an AWS EC2 instance with docker-compose up --build . It works as expected and is accessible remotely from the EC2 public IP when I use port 80 i.e., "80:80" as shown in the docker-compose file.
However, if I change to another port such as "5106:80", it is not accessible from a remote host using <public IPv4 address>:5106 even though it's available locally if I ssh unto the EC2 instance and …
我目前正在 Amazon Elastic Beanstalk 上运行 Python Flask 应用程序。当我测试应用程序时,它在本地一切正常(我使用 Postman 发送 GET & POST 请求)。但是,在 AWS 上,它不起作用,因为到达我的 EC2 实例(在负载均衡器后面)的请求不包含Authorization标头。负载平衡器似乎剥离了标头。我在这里做错了吗?
这是我在本地和 Elastic Beanstalk 上打印标题时得到的比较。
本地
[2017-07-04 13:18:14,650] [INFO] [common.decorators] Headers = Host: localhost:5000
Connection: keep-alive
Content-Length: 151
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Cache-Control: no-cache
Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Content-Type: application/json
Authorization: Bearer ad9fd4d9-6ce6-497b-855a-dcebebdad65b
Postman-Token: xxxxx
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
弹性豆茎:
[2017-07-04 17:27:03,813] [DEBUG] [common.decorators] Headers = Accept-Language: en-US,en;q=0.8
Accept: …
amazon-ec2 amazon-web-services http-headers amazon-elastic-beanstalk elastic-load-balancer
有人可以帮我弄清楚以下代码有什么问题.这是一个Python应用程序试图使用Connector/Python从mysql数据库中进行选择
number = '+12345678901'
cursor.execute('SELECT * FROM channel WHERE phone_number = %s', (number))
Run Code Online (Sandbox Code Playgroud)
它产生以下错误:
1064(42000):您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第1行的'%s'附近使用正确的语法
当我检查mysql日志时,我看到以下内容:
SELECT*FROM channel WHERE phone_number =%s
这意味着它不能代替电话号码.
java ×5
amazon-ec2 ×3
apache ×1
flask ×1
hashcode ×1
http-headers ×1
junit ×1
maven ×1
mod-wsgi ×1
mysql ×1
native-base ×1
python ×1
python-2.7 ×1
react-native ×1
spring ×1
spring-3 ×1
treeset ×1
unit-testing ×1