用于java的弱并发堆栈

时间:2015-11-22 19:12:38

标签: java collections

在java中使用弱引用或软引用的wait-free堆栈有哪些选项?

到目前为止,我已经提出:

from tkinter import *
import threading


# Run the Tkinter GUI in a separate thread
class GUI(threading.Thread):
    def __init__(self, listener):
        self.listener = listener
        threading.Thread.__init__(self)
        self.start()

    def callback(self):
        self.root.quit()

    def run(self):
        self.root = Tk()
        self.root.protocol("WM_DELETE_WINDOW", self.callback)
        self.root.title("2048")
        if self.listener:
            self.root.bind("<Key>", self.listener)

        self.gameGUI = GameGUI(self.root)
        self.gameGUI.pack()

        self.root.mainloop()

    def get_game_gui_instance(self):
        return self.gameGUI


class GameGUI(Canvas):
    cellColors = {0: "#CCC0B3", 2: "#eee4da", 4: "#ede0c8", 8: "#f2b179", 16: "#f59563", 32: "#f67c5f", 64: "#f65e3b", 128: "#edcf72", 256: "#edcc61", 512: "#edc850", 1024: "#edc53f", 2048: "#edc22e", 4096: "#3c3a32"}
    boardSize = 4

    def __init__(self, master):
        Canvas.__init__(self, master)
        self.cells = []
        self.initUI(150)

    def initUI(self, cellSize):
        for row in range(0, 4):
            self.cells.append([])
            for column in range(self.boardSize):
                cell = Frame(self, width=cellSize, height=cellSize)
                cell.grid(row=row, column=column, padx=4, pady=4)
                cell.pack_propagate(0)

                tile = Label(cell, bg="#CCC0B3", font=("Helvetica", 35, "bold"))
                tile.pack(fill=BOTH, expand=1)
                self.cells[-1].append(tile)

    def setTile(self, value, x, y):
        self.cells[y][x].config({
            "text": str(value) if value else '',
            "fg": ("#776E65" if value < 8 else "#f9f6f2"),
            "bg": self.cellColors[min(4096, value)]})

    def drawBoard(self, board):
        for col in range(len(board)):
            for row in range(len(board)):
                self.setTile(board[col][row], row, col)

问题是这会在双端队列中留下未收集的引用, 并且实现集合将不是最佳的,因为它需要遍历双端队列。

0 个答案:

没有答案