gpt4 book ai didi

java - "CopyOnWriteArrayList"和 "ConcurrentHashMap"可以序列化吗?

转载 作者:行者123 更新时间:2023-12-02 05:14:28 25 4
gpt4 key购买 nike

我有一个使用 RMI 的类传送。但我不确定这些线程安全对象是否可以序列化。有人尝试过吗?

更新skaffman说是的,但是我序列化失败了。

这是我传送的类(class)。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.shisoft.beans;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
*
* @author Shisoft
*/
public class WhatzNewList {

ConcurrentHashMap<String, CopyOnWriteArrayList<WhatzNewEntry>> WhatzNewTable = new ConcurrentHashMap<String, CopyOnWriteArrayList<WhatzNewEntry>>();
String user;

public ConcurrentHashMap<String, CopyOnWriteArrayList<WhatzNewEntry>> getWhatzNewTable() {
return WhatzNewTable;
}

public void setWhatzNewTable(ConcurrentHashMap<String, CopyOnWriteArrayList<WhatzNewEntry>> WhatzNewTable) {
this.WhatzNewTable = WhatzNewTable;
}

public String getUser() {
return user;
}

public void setUser(String usere) {
this.user = usere;
}

public WhatzNewList(String user) {
this.user = user;
}
}

这是类WhatzNewEntry

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.shisoft.beans;

import java.util.Date;

/**
*
* @author Shisoft
*/
public class WhatzNewEntry {
String Title;
String context;
String contact;
Date Time;

public Date getTime() {
return Time;
}

public void setTime(Date Time) {
this.Time = Time;
}

public String getTitle() {
return Title;
}

public void setTitle(String Title) {
this.Title = Title;
}

public String getContact() {
return contact;
}

public void setContact(String contact) {
this.contact = contact;
}

public String getContext() {
return context;
}

public void setContext(String context) {
this.context = context;
}

}

也许斯卡夫曼是对的,但是这里有什么问题吗?

最佳答案

它们都实现了java.io.Serialized。所以是的,它们可以被序列化。

当然,它们的内容是否可以序列化完全是另一个问题。

关于java - "CopyOnWriteArrayList"和 "ConcurrentHashMap"可以序列化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4867028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com