我正在使用Apache http客户端4.3.2发送get请求.我所做的是:
private final RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(1000)
.setConnectionRequestTimeout(1000)
.setSocketTimeout(1000)
.build();
private final HttpClient client = HttpClientBuilder.create()
.disableAuthCaching()
.disableAutomaticRetries()
.disableConnectionState()
.disableContentCompression()
.disableCookieManagement()
.disableRedirectHandling()
.setDefaultRequestConfig(requestConfig)
.build();
Run Code Online (Sandbox Code Playgroud)
并在发送请求时:
HttpGet request = null;
try {
request = new HttpGet(url);
if (client.execute(request).getStatusLine().getStatusCode() == 200) {
/* do some work here */
}
} catch (Exception e) {
Logger.error(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我的一些请求仍然需要很长时间才能超时.这是异常的堆栈跟踪:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136) …Run Code Online (Sandbox Code Playgroud) 我已下载内核2.6.38-5并想添加系统调用.我做了以下事情:
我已将系统调用添加到系统调用表中;
<src folder>/arc/x86/kernel/syscall_table_32.S
.long sys_mycall
Run Code Online (Sandbox Code Playgroud)我添加了系统电话号码;
<src folder>/include/asm-generic/unistd.h
#define __NR_mycall 244
__SYSCALL(__NR_mycall, sys_mycall)
Run Code Online (Sandbox Code Playgroud)我已将原型添加到syscalls.h;
<src follder>/include/linux/syscalls.h
asmlinkage long sys_mycall(long input);
Run Code Online (Sandbox Code Playgroud)而且,这是我的系统调用;
asmlinkage long sys_mycall(long input) {
return (input * 2);
}
Run Code Online (Sandbox Code Playgroud)我也编辑了Makefile.
现在编译之后,当我通过syscall()它使用它时,我将BAD ADDRESSerrno设置为14.
我该怎么办?
我对"引用特定类型的任意对象的实例方法"背后的概念感到困惑.Oracle 文档有一个关于此的示例:
String[] stringArray = { "Barbara", "James", "Mary", "John", "Patricia", "Robert", "Michael", "Linda" };
Arrays.sort(stringArray, String::compareToIgnoreCase);
Run Code Online (Sandbox Code Playgroud)
我在这种方法参考中看到的大多数例子都是这样的:如果lambda是这样的:x -> x.func()那么你就可以这样写ClassOfX::func.文档中的示例说:
方法引用String :: compareToIgnoreCase的等效lambda表达式将具有形式参数列表(String a,String b),其中a和b是用于更好地描述此示例的任意名称.方法引用将调用方法a.compareToIgnoreCase(b).
现在的问题是:像任何两个参数的lambda (a, b) -> a.func(b)的func方法必须是第一个参数,拉姆达的第二个参数的实例方法将作为参数传递给该方法通过?如果我们有多个参数lambda那么func方法必须是lambda 的第一个参数的实例方法,而lambda的其他参数将按照lambda func中出现的顺序传递给它?我的意思是,而不是(a, b, c) -> a.func(b, c)我们可以写ClassOfA::func
对不起我的英语.我希望我能清楚地解决这个问题.
我正在寻找最常用的5个实时操作系统.我在Google上搜索过,维基百科有一个RTOS列表,但它们是随机排列的,我也不相信所有这些都是实时运行的.
还有一个问题:我们可以包含Windows 7吗?当我们设置5个任务的优先级时,例如实时.
我正在阅读"使用JAX-RS 2.0的RESTful Java"一书.我完全混淆了异步JAX-RS,所以我把所有问题都集中在一起.这本书写了这样的异步服务器:
@Path("/customers")
public class CustomerResource {
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_XML)
public void getCustomer(@Suspended final AsyncResponse asyncResponse,
@Context final Request request,
@PathParam(value = "id") final int id) {
new Thread() {
@Override
public void run() {
asyncResponse.resume(Response.ok(new Customer(id)).build());
}
}.start();
}
}
Run Code Online (Sandbox Code Playgroud)
Netbeans创建这样的异步服务器:
@Path("/customers")
public class CustomerResource {
private final ExecutorService executorService = java.util.concurrent.Executors.newCachedThreadPool();
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_XML)
public void getCustomer(@Suspended final AsyncResponse asyncResponse,
@Context final Request request,
@PathParam(value = "id") final int id) {
executorService.submit(new Runnable() {
@Override
public void …Run Code Online (Sandbox Code Playgroud) Linux编程接口手册提到了一种在多线程程序中处理异步信号的方法:
- 所有线程都阻止进程可能接收的所有异步信号.最简单的方法是在创建任何其他线程之前阻止主线程中的信号.随后创建的每个线程都将继承主线程信号掩码的副本.
- 创建,使用接受传入信号的单个专用线程
sigwaitinfo(),sigtimedwait()或sigwait().这种方法的优点是同步接收异步生成的信号.由于它接受传入信号,专用线程可以安全地修改共享变量(在互斥控制下)并调用非异步安全功能.它还可以发信号通知条件变量,并且可以实现其他线程和进程通信和同步机制.
现在的问题是:
Linux编程接口书有一段代码(生产者/消费者)来展示条件变量的工作原理:
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static int avail = 0;
while (TRUE) {
s = pthread_mutex_lock(&mtx);
while (avail == 0) { /* Wait for something to consume */
s = pthread_cond_wait(&cond, &mtx);
}
while (avail > 0) { /* Consume all available units */
avail--;
}
s = pthread_mutex_unlock(&mtx);
}
Run Code Online (Sandbox Code Playgroud)
为什么我们用pthread_mutex_lock的while?为什么我们不用它if?
我们有一个具有以下配置的 KStreams 应用程序:
props.setProperty(RETRIES_CONFIG, String.valueOf(Integer.MAX_VALUE));
props.setProperty(RETRY_BACKOFF_MS_CONFIG, "5000"); // 5 seconds
props.setProperty(RECONNECT_BACKOFF_MS_CONFIG, "5000"); // 5 seconds
props.setProperty(REQUEST_TIMEOUT_MS_CONFIG, "5000"); // 5 seconds
props.setProperty(SESSION_TIMEOUT_MS_CONFIG, "25000"); // 25 seconds session timeout
props.setProperty(MAX_POLL_RECORDS_CONFIG, "100"); // 100 records per poll
props.setProperty(MAX_POLL_INTERVAL_MS_CONFIG, String.valueOf(Integer.MAX_VALUE));
// do not add any more time to window retention period, delete immidiately
props.setProperty(WINDOW_STORE_CHANGE_LOG_ADDITIONAL_RETENTION_MS_CONFIG, "0");
Run Code Online (Sandbox Code Playgroud)
即使非常大MAX_POLL_INTERVAL_MS_CONFIG,我们也会看到类似的错误(json 中的格式化异常):
{
"@timestamp": "2020-02-07T15:30:19.631Z",
"message": "[Consumer clientId=client-03a38ada-b39c-497a-acd4-aa95066fdc8a-StreamThread-6-consumer, groupId=group-name] Offset commit failed on partition group-name-repartition-3 at offset 9066: The coordinator is not aware of this member.",
"logger_name": …Run Code Online (Sandbox Code Playgroud) 大多数Hadoop MapReduce程序都是这样的:
public class MyApp extends Configured Implements Tool {
@Override
public int run(String[] args) throws Exception {
Job job = new Job(getConf());
/* process command line options */
return job.waitForCompletion(true) ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new MyApp(), args);
System.exit(exitCode);
}
}
Run Code Online (Sandbox Code Playgroud)
有什么用Configured?由于Tool和Configured都有getConf()和setConf()共同点.它为我们的应用程序提供了什么?
我真正想要的是在JOOQ中编写以下查询:
stmt = connection.prepareStatement(
"INSERT INTO `tbl` (`name`, `service_id`, `device_id`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `id` = LAST_INSERT_ID(`id`)",
Statement.RETURN_GENERATED_KEYS
);
Run Code Online (Sandbox Code Playgroud)
我无法在JOOQ中找到一种方法.可能吗?
java ×5
c ×3
pthreads ×2
apache-kafka ×1
asynchronous ×1
hadoop ×1
java-8 ×1
jax-rs ×1
jooq ×1
kernel ×1
lambda ×1
mapreduce ×1
mutex ×1
mysql ×1
real-time ×1
rest ×1
rtos ×1
signals ×1
system-calls ×1
timeout ×1
toolrunner ×1
web-services ×1