我理解@Native
注释的使用.
指示可以从本机代码引用定义常量值的字段.注释可以用作生成本机头文件的工具的提示,以确定是否需要头文件,如果需要,它应该包含哪些声明.
然而,在阅读Java源代码我注意到,在阶级Integer
和Long
的SIZE
常数@Native
,而它不是浮动,字节,双,短期和字符.
请注意,SIZE常量表示用于表示实际值的位数.
public static final int SIZE = 8;//Byte
public static final int SIZE = 16;//Character
public static final int SIZE = 16;//Short
public static final int SIZE = 32;//Float
@Native public static final int SIZE = 32;//Integer
@Native public static final int SIZE = 64;//Long
public static final int SIZE = 64;//Double
Run Code Online (Sandbox Code Playgroud)
编辑:我刚刚注意到,这也适用于MAX_VALUE
和MIN_VALUE
同一类的.
编辑2:我有空闲时间对此进行一些研究,并查看Long,Float等类的头文件,我希望找出常量不存在于其他头文件中,但不幸的是它们是.
static const jint SIZE = 8L;//java/lang/Byte.h
static …
Run Code Online (Sandbox Code Playgroud) 我们都知道Java有一个缓存Integer
(和其他一些类型)的数量在该范围内[-128, 127]
被认为是"常用".
缓存的设计如下:
private static class IntegerCache {
static final int low = -128;
static final int high;
static final Integer cache[];
static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the …
Run Code Online (Sandbox Code Playgroud) 我使用的是新 java.net.http.HttpClient
与sendAsync
方法.该HttpClient
是Singelton内创建一次像这样:
HttpClient.newBuilder().build()
所以真的没什么特别的.
这些请求可以是POST
,GET
但我不知道是哪个引起了麻烦.
每天只有几个请求,但有时一个线程使用100%的cpu核心.并不是迫在眉睫,而是在请求完成一段时间后.
所以我做了一个线程转储,甚至有两个无限循环发生,以下2个线程突出:
"HttpClient-4-Worker-5" #144 daemon prio=5 os_prio=0 cpu=511298.10ms elapsed=520.71s tid=0x00007f684403e800 nid=0x2d6b runnable [0x00007f68ac162000]
java.lang.Thread.State: RUNNABLE
at jdk.internal.net.http.common.SSLFlowDelegate$Writer.processData(java.net.http@11.0.2/SSLFlowDelegate.java:771)
at jdk.internal.net.http.common.SSLFlowDelegate$Writer$WriterDownstreamPusher.run(java.net.http@11.0.2/SSLFlowDelegate.java:645)
at jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:147)
at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(java.net.http@11.0.2/SequentialScheduler.java:198)
at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(java.net.http@11.0.2/SequentialScheduler.java:271)
at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(java.net.http@11.0.2/SequentialScheduler.java:224)
at jdk.internal.net.http.common.SSLFlowDelegate$Writer.triggerWrite(java.net.http@11.0.2/SSLFlowDelegate.java:722)
at jdk.internal.net.http.common.SSLFlowDelegate.doHandshake(java.net.http@11.0.2/SSLFlowDelegate.java:1024)
at jdk.internal.net.http.common.SSLFlowDelegate.doClosure(java.net.http@11.0.2/SSLFlowDelegate.java:1094)
at jdk.internal.net.http.common.SSLFlowDelegate$Reader.unwrapBuffer(java.net.http@11.0.2/SSLFlowDelegate.java:500)
at jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(java.net.http@11.0.2/SSLFlowDelegate.java:389)
- locked <0x00000000fba68950> (a java.lang.Object)
at jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(java.net.http@11.0.2/SSLFlowDelegate.java:263)
at jdk.internal.net.http.common.SequentialScheduler$SynchronizedRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:175)
- locked <0x00000000fbbca3e8> (a java.lang.Object)
at jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:147)
at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(java.net.http@11.0.2/SequentialScheduler.java:198)
at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.2/ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.2/ThreadPoolExecutor.java:628)
at java.lang.Thread.run(java.base@11.0.2/Thread.java:834)
Locked ownable …
Run Code Online (Sandbox Code Playgroud) 我与Java编程完全脱节,并且正在谷歌的Udacity课程作为复习.我正在浏览Sunshine应用程序的第1课,讲师通过声明一个字符串数组然后将其转换为ArrayList来选择创建虚假数据.
代码如下:
String[] data = {
"Mon 6/23?- Sunny - 31/17",
"Tue 6/24 - Foggy - 21/8",
"Wed 6/25 - Cloudy - 22/17",
"Thurs 6/26 - Rainy - 18/11",
"Fri 6/27 - Foggy - 21/10",
"Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
"Sun 6/29 - Sunny - 20/7"
};
List<String> weatherForecast = new ArrayList<>(Arrays.asList(data));
Run Code Online (Sandbox Code Playgroud)
我想知道使用这种转换方法有什么好处吗?为什么不立即将数据声明为ArrayList:
ArrayList weatherForecast = new ArrayList();
weatherForecast.add("Today - Sunny - 88/63");
weatherForecast.add("Tomorrow - Foggy = 70/46");
weatherForecast.add("Weds - Cloudy - 72/63");
weatherForecast.add("Thurs 6/26 - Rainy …
Run Code Online (Sandbox Code Playgroud) 我升级到Luna并遇到自动格式化问题,更具体地说是自动缩进.About Eclipse对话框验证我正在运行4.4.0.
当代码在保存时自动缩进时,它似乎在两种不同的缩进方式之间来回跳转.注意缩进的级别:
doSomething( "arg0",
"arg1" );
Run Code Online (Sandbox Code Playgroud)
和
doSomething( "arg0",
"arg1" );
Run Code Online (Sandbox Code Playgroud)
当使用像git这样的SCM时,这非常烦人.是什么导致了这个?怎么修好?
如何将日期为"2012-08-03"的列转换为Postgres中的日期?
public class GuardedBlock {
private boolean guard = false;
private static void threadMessage(String message) {
System.out.println(Thread.currentThread().getName() + ": " + message);
}
public static void main(String[] args) {
GuardedBlock guardedBlock = new GuardedBlock();
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
guardedBlock.guard = true;
threadMessage("Set guard=true");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
threadMessage("Start waiting");
while (!guardedBlock.guard) {
//threadMessage("Still …
Run Code Online (Sandbox Code Playgroud) 我有代码:
int[] values = { 1, 4, 9, 16 };
Stream<Integer> ints = Stream.of(values);
Run Code Online (Sandbox Code Playgroud)
这给了我编译错误.但:
int[] values = { 1, 4, 9, 16 };
Stream<Integer> ints = Stream.of(new Integer[] {1, 4, 9, 16});
Run Code Online (Sandbox Code Playgroud)
不这样做.为什么?
我试图从Web资源使用Jersey下载SWF文件.
我写了以下代码,但无法正确保存文件:
Response response = webResource.request(MediaType.APPLICATION_OCTET_STREAM)
.cookie(cookie)
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
String binarySWF = response.readEntity(String.class);
byte[] SWFByteArray = binarySWF.getBytes();
FileOutputStream fos = new FileOutputStream(new File("myfile.swf"));
fos.write(SWFByteArray);
fos.flush();
fos.close();
Run Code Online (Sandbox Code Playgroud)
保存假设响应确实返回SWF文件,作为response.getMediaType
返回application/x-shockwave-flash
.
但是,当我尝试打开SWF时,没有任何事情发生(也没有错误),这表明我的文件不是从响应中创建的.
我有一个构造函数(用于自动生成的类),有255个参数.在linux上使用ant和javac 1.6.0_02.这个课程编写得很好,一切都很好.
但是,当我尝试使用jdk 1.6在windows xp上的eclipse中编译同一个类时,我收到以下错误
Too many parameters, parameter BLAH is exceeding the limit of 255 words eligible for method parameters
Run Code Online (Sandbox Code Playgroud)
BLAH
是第256个参数.
有办法克服这个问题吗?更改自动生成的类不是一个选项,因为我需要在每次编译时更改它或更改生成器.这两个选项都是不可接受的,因为我们已经可以在linux上获得这个类.
PS:对于那些感兴趣的人,java类是使用JacORB从IDL文件生成的.不幸的是,由于它定义了我们的软件和其他系统之间的接口,因此无法减少类中的参数数量.