问题类似于以下两个问题.
但我仍然无法完全理解它.
到目前为止,我认为以下代码中的read()方法将因空文件'test.txt'而阻塞.
FileInputStream fis = new FileInputStream("c:/test.txt");
System.out.println(fis.read());
System.out.println("to the end");
Run Code Online (Sandbox Code Playgroud)
实际上它会打印-1,我想知道为什么.
javadoc说如果还没有输入,则此方法会阻塞.
什么" 没有输入可用 "是什么意思?
谢谢.
Path file = Paths.get("c:/large.log");
AsynchronousFileChannel channel = AsynchronousFileChannel.open(file);
final ByteBuffer buffer = ByteBuffer.allocate(1000);
channel.read(buffer, 0, buffer,
new CompletionHandler<Integer, ByteBuffer>() {
public void completed(Integer result, ByteBuffer attachment) {
System.out.println(new String(buffer.array()));
}
});
Run Code Online (Sandbox Code Playgroud)
这样,我就可以从large.log中读取前1000字节。如果我不想分配更大的字节数组,如 ByteBuffer.allocate(1000*1000),我如何读取以下日志。因为我认为这会导致OutOfMemory。
有人可以给我示例代码吗? 谢谢。
ps:我可以用JIO循环读取大文件,因为我可以检查java.io.BufferedReader.read()的返回值。但我不知道NIO2怎么办。
2013-12-15T22:52:05.154-0500:1.078:[全GC(系统)[PSYoungGen:1600K-> 0K(27776K)] [PSOldGen:0K-> 1502K(63360K)] 1600K-> 1502K(91136K)[ PSPermGen:9139K-> 9139K(65536K)],0.0282750秒] [时间:用户= 0.03 sys = 0.00,实际= 0.03秒]
以上是日志文件中的日志片段.我通过添加jvm参数得到了日志,如下所示.
-Xloggc:/tmp/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps
Run Code Online (Sandbox Code Playgroud)
现在我想知道是什么意思
[PSOldGen:0K-> 1502K(63360K)] 1600K-> 1502K(91136K)
怎么会发生?
当我将许多小文件存储到HDFS中时,它们会存储在一个块中吗?
在我看来,根据这个讨论,这些小文件应该存储在一个块中: HDFS块大小与实际文件大小相同
我想使用sinopia建立一个私人npm注册表,我执行'npm install -g sinopia'.但是有些错误消息如下所示.
> crypt3@0.1.8 install /usr/local/lib/node_modules/sinopia/node_modules/crypt3
> node-gyp rebuild
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/4.2.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/sinopia/node_modules/crypt3/.node-gyp"
make: Entering directory `/usr/local/lib/node_modules/sinopia/node_modules/crypt3/build'
CXX(target) Release/obj.target/crypt3/crypt3.o
In file included from ../crypt3.cc:7:0:
../node_modules/nan/nan.h:261:25: error: redefinition of âtemplate<class T> v8::Local<T> _NanEnsureLocal(v8::Local<T>)â
NAN_INLINE v8::Local<T> _NanEnsureLocal(v8::Local<T> val) {
^
../node_modules/nan/nan.h:256:25: error: âtemplate<class T> v8::Local<T> _NanEnsureLocal(v8::Handle<T>)â previously declared here
NAN_INLINE v8::Local<T> _NanEnsureLocal(v8::Handle<T> val) {
^
../node_modules/nan/nan.h:661:13: error: ânode::smallocâ …Run Code Online (Sandbox Code Playgroud) 下面是我的 jpa 代码。
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
Root e = cq.from(Student.class);
cq.where(cb.greaterThan(e.get("id"), 3));
Query query = entityManager.createQuery(cq);
List<Student> students = query.getResultList();
Run Code Online (Sandbox Code Playgroud)
我想得到所有id大于3的学生。谢谢。
我在谷歌上搜索了很多,发现很多人在https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/seq-generator.html 中说的allocationSize意思是 ' After 'allocationSize' is reached, the next id will be retrieved from the database sequence again' 。
它的意思是 jpa 文件。
The amount to increment by when allocating sequence numbers from the sequence
Run Code Online (Sandbox Code Playgroud)
它似乎与sql中的“增量”相同。
哪一个是对的?由于我在h2/jpa中测试过,这个allocationSize不起作用,即使设置为20,sequence的下一个值也不会增加20。
我也对 sql 中的“缓存”感到困惑。
总之,以下面为例。
CREATE SEQUENCE ITEM_ID_SEQ START WITH 1 INCREMENT BY 100 cache 30;
Run Code Online (Sandbox Code Playgroud)
INCREMENT BY 100、缓存 30和jpa的allocationSize 有什么区别。
谢谢。
我基于springboot创建了一个用户管理服务。
该用户将有一个列表附件,这样用户和依恋的关系是一对多。
我在这里忽略了插入逻辑,因为我的问题是关于延迟加载以及何时打开和关闭entitymanager。以下是实体,控制器,服务,Dao,存储库相关的代码。
实体
@Entity
@Table(name="User")
public class UserInfoEntity {
private long id;
private String mail;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "userInfoEntity", cascade = CascadeType.ALL)
private List<UserAttachmentEntity> attachmentList = new ArrayList<>();
}
@Entity
@Table(name = "ATTACHMENT")
public class UserAttachmentEntity {
private long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userRequestId")
private UserInfoEntity userInfoEntity;
}
Run Code Online (Sandbox Code Playgroud)
服务
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override …Run Code Online (Sandbox Code Playgroud) 我正在浏览下面的文章。 https://facebook.github.io/react/docs/react-component.html#setstate
我发现之前 setState 看起来像下面。
this.setState({mykey: 'my new value'});
Run Code Online (Sandbox Code Playgroud)
但是有一个像下面这样的新签名。
this.setState((prevState, props) => {
return {myInteger: prevState.myInteger + props.step};
});
Run Code Online (Sandbox Code Playgroud)
官方文档解释说“这将在设置任何值之前查询 state 和 props 的先前值的原子更新。”。 但是我不理解。我知道不能保证对 setState 调用的同步操作。但是新的签名方法会是同步的还是有其他影响?
有人可以解释一下吗?
以下是我的jsfiddle。 https://jsfiddle.net/xuhang1128/1wff2rqv/5/
主要代码如下。
.design2-statusMonitor {
margin-top: 20px;
}
.design2-statusMonitor .list-group-item {
display: inline-block;
background-color: transparent;
//border-right: 0.5px solid #CAD5E0;
border-top: 1px solid #CAD5E0;
border-bottom: 1px solid #CAD5E0;
width: auto;
}
.design2-statusMonitor .list-group-item.selected {
background-color: #2f749a;
}
.design2-statusMonitor .list-group-item:focus {
outline: none;
}
.design2-statusMonitor .list-group-item:after {
content: "";
width: 9px;
height: 9px;
position: absolute;
right: -6px;
top: 43%;
z-index: 2;
background-color: white;
border-top: 2px solid #CAD5E0;
border-right: 2px solid #CAD5E0;
transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
Run Code Online (Sandbox Code Playgroud)
下面是我单击它时的屏幕截图。您可以看到,当我单击它时,背景色似乎没有完全填充按钮,左右边缘是否存在?当我单击下面的按钮时,如何消除该间隙?

举个例子:
public class Hello {
public static void main(String[] args) {
try {
OutputStream os = new FileOutputStream(new File("c.txt"));
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么c.txt在当前项目的根路径中生成除了java文件的相同路径之外?

谢谢.

点击搜索按钮后,没有任何反应.搜索框没有出现.Below是我的menu.xml.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.support.v7.widget.SearchView" />
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose"
android:showAsAction="never" />
</menu>
Run Code Online (Sandbox Code Playgroud)
虽然搜索小部件没有显示在操作栏上,但是在我在方法onCreateOptionsMenu中添加以下代码之前没有抛出异常.
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
Run Code Online (Sandbox Code Playgroud)
详细的例外情况如下.
01-19 14:17:00.222: W/ResourceType(2064): No package identifier when getting value for resource number 0x00000000
01-19 14:17:00.222: W/MenuInflater(2064): Cannot instantiate class: android.support.v7.widget.SearchView
01-19 14:17:00.222: W/MenuInflater(2064): java.lang.reflect.InvocationTargetException
01-19 14:17:00.222: W/MenuInflater(2064): at java.lang.reflect.Constructor.newInstance(Native Method)
01-19 14:17:00.222: W/MenuInflater(2064): at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
01-19 14:17:00.222: W/MenuInflater(2064): at android.view.MenuInflater$MenuState.newInstance(MenuInflater.java:514)
01-19 14:17:00.222: W/MenuInflater(2064): at android.view.MenuInflater$MenuState.setItem(MenuInflater.java:471)
01-19 14:17:00.222: W/MenuInflater(2064): …Run Code Online (Sandbox Code Playgroud)