在此代码中,当我从列表中间选择一个元素并删除时,所选元素下面的元素也会从"视图"中删除.但它们存在于数据库中,并在应用程序运行时再次出现.请帮我解决这个错误.谢谢.
DeleteController delController = new DeleteController();
delController.deleteInfo(dbId);
this.jList1 = list;
AbstractListModel model = (AbstractListModel) jList1.getModel();
int numberElements = model.getSize();
final String[] allElements = new String[numberElements + 1];
for (int i = 0; i < numberElements - 1; i++) {
String val = (String) model.getElementAt(i);
if (!dbId.equals(val)) {
allElements[i] = (String) model.getElementAt(i);
}
}
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = allElements;
public int getSize() {
return strings.length;
}
public Object getElementAt(int i) {
return strings[i];
}
});
Run Code Online (Sandbox Code Playgroud) 请检查我的多线程代理检查器代码.它总是检查相同的代理.我想我需要使用锁吗?但是当我使用锁时,它只使用一个线程.但通常它是多线程的.这是什么问题?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Threading;
namespace ProxyChecker
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void clearButton_Click(object sender, EventArgs e)
{
proxyList.Items.Clear();
}
private void clearButton2_Click(object sender, EventArgs e)
{
checkedList.Items.Clear();
}
Thread[] checkerThread;
int checking;
int beenChecked;
private bool isRunning;
private delegate void filterProxyHandler(int Index, bool Valid);
static readonly object _locker = new object();
private …
Run Code Online (Sandbox Code Playgroud) 这个代码有时抛出一个Exception,即使我在run方法块中使用了 synchronized
Method ,我在一个上添加和删除元素.removeFirst
synchronized
synchronizedList
public class NameDropper extends Thread {
private NameList n1;
public NameDropper(List list) {
this.n1 = new NameList(list);
}
public static void main(String[] args) {
List l = Collections.synchronizedList(new LinkedList());
NameDropper n = new NameDropper(l);
n.n1.add("Ozymandias");
Thread[] t = new NameDropper[10];
for (int i = 1; i <= 10; i++) {
t[i - 1] = new NameDropper(l);
t[i - 1].setName("T" + Integer.toString(i - 1));
t[i - 1].start();
}
}
public void run() {
synchronized …
Run Code Online (Sandbox Code Playgroud) 在此测试线程代码中的代码中,线程调用两个方法addToTotal()
,countPrimes()
但只有前者标记为synchronized.
countPrimes()
在执行时阻止交错的原因.不是countPrimes()
i,min,max,count 使用的变量也不是共享资源.又是怎么回事isPrime()
这是由所谓的countPrimes()
?
public class ThreadTest2 {
private static final int START = 3000000;
private static int total;
synchronized private static void addToTotal(int x) {
total = total + x;
System.out.println(total + " primes found so far.");
}
private static class CountPrimesThread extends Thread {
int count = 0;
int min, max;
public CountPrimesThread(int min, int max) {
this.min = min;
this.max = max;
}
public void …
Run Code Online (Sandbox Code Playgroud) 我的网络服务的一个子任务是在数据库中保存文件(以及一些元数据)。
Web服务基于ServiceStack及其ORMlite版本。
所以我创建了一个代表数据库中附件的小类:
public class Attachment {
public string Description { get; set; }
public string FileName { get; set; }
public string Type { get; set; }
public byte[] Data { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是实际文件
MemoryStream ms = new MemoryStream(webclient.DownloadData(...));
byte[] data = new byte[...];
ms.Read(data, 0, data.Length);
Attachment file = new Attachment() {
/* all the other stuff */
Data = data
};
Run Code Online (Sandbox Code Playgroud)
直到现在都没有问题... :)
现在我拥有了将这个文件放入数据库所需的一切。所以让我们开始吧......
dbCmd.Insert<Attachment>(file);
Run Code Online (Sandbox Code Playgroud)
还有问题...
SqlException: "Operand type …
Run Code Online (Sandbox Code Playgroud) java ×3
c# ×2
java-ee ×1
jlist ×1
locking ×1
servicestack ×1
sockets ×1
sql-server ×1
swing ×1
synchronized ×1